PDA

View Full Version : default برایcode first



sunn789
دوشنبه 02 تیر 1393, 15:37 عصر
سلام اگه بخواهیم در Code First برای ستونها default تعریف کنیم چگنه باد این کا ررو کرد

aroshanzamir
دوشنبه 02 تیر 1393, 17:00 عصر
public partial class Student
{
public Student()
{
this.Name = "ANDY";
this.Family = "Madadian";
}
public int Id { get; set; }
public string Name { get; set; }
public string Family { get; set; }
}

helpsos
سه شنبه 03 تیر 1393, 08:49 صبح
زمانی که از Enable Migration استفاده می کنید در فایل Configuration داخل پوشه Migration یک متد به صورت زیر وجود دارد که می توان از آن استفاده نمود.
protected override void Seed(Partak.Models.ApplicationDbContext context) {
// This method will be called after migrating to the latest version.


// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}