2013-02-11 55 views
2

我需要每行的唯一散列值,所以我創建了一個類型爲Guid的列。爲什麼刪除了Guid列?

public class SendingLog 
{ 
    [Key] 
    public int SendingLogId { get; set; } 

    [Required, ForeignKey("Apartment")] 
    public int ApartmentId { get; set; } 

    public virtual Apartment Apartment { get; set; } 

    Guid RowGuid { set; get; } 

    [MaxLength(256), Required] 
    public string Email { get; set; } 

    [Required] 
    public DateTime SentTime { get; set; } 

    public int SentByUserId { get; set; } 
} 

但是,代碼第一次遷移生成以下代碼。

public override void Up() 
{ 
    CreateTable(
     "dbo.SendingLogs", 
     c => new 
      { 
       SendingLogId = c.Int(nullable: false, identity: true), 
       ApartmentId = c.Int(nullable: false), 
       Email = c.String(nullable: false, maxLength: 256), 
       SentTime = c.DateTime(nullable: false), 
       SentByUserId = c.Int(nullable: false), 
      }) 
     .PrimaryKey(t => t.SendingLogId) 
     .ForeignKey("dbo.Apartments", t => t.ApartmentId, cascadeDelete: true) 
     .Index(t => t.ApartmentId); 
} 

爲什麼Guid列被刪除?

回答

4

這是因爲它的範圍是private

通過在前面省略public,代碼第一個遷移生成器不會將其視爲需要擔心的屬性。

將其更改爲:

public Guid RowGuid { set; get; }