SORU
29 HAZİRAN 2010, Salı


Nasıl varsayılan'un POCO değeri için EF CF set?

Varlık Çerçevesi 4, Kod, Yalnızca (CTP3), nasıl POCO. EntityConfiguration sınıfta bir özellik için varsayılan değer ayarlama mı?

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime CreatedOn { get; set; }
}

public class PersonConfiguration : EntityConfiguration<Person>
{
    public PersonConfiguration()
    {
        Property(p => p.Id).IsIdentity();
        Property(p => p.Name).HasMaxLength(100);

        //set default value for CreatedOn ?
    }
}

CEVAP
24 ŞUBAT 2012, Cuma


Varlık Çerçevesi 4.3 sürümü ile Göçler ile bunu yapabilirsiniz.

EF 4.3 Code First Migrations Walkthrough

Senin örnek olarak kullanarak şöyle bir şey olurdu:

public partial class AddPersonClass : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "People",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Name = c.String(maxLength: 100),
                    CreatedOn = c.DateTime(nullable: false, defaultValue: DateTime.UtcNow)
                })
            .PrimaryKey(t => t.Id);
    }

    public overide void Down()
    {
        // Commands for when Migration is brought down
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • boburnham

    boburnham

    11 Temmuz 2006
  • girleffect

    girleffect

    20 Mayıs 2008
  • ShoSho

    ShoSho

    20 Ocak 2010