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

  • cdgotx

    cdgotx

    8 Kasım 2011
  • Flash CS6 Video Tutorials for Beginners (Actionscript 3 Gaming)

    Flash CS6 Vi

    14 EYLÜL 2012
  • natescamp

    natescamp

    30 NİSAN 2009