0
我有以下ERD,並希望將其轉換爲EF 4.1 Code First類。爲了簡單起見,我只專注於前兩個實體。ERD代碼第一類
作者>引用。
是具有我對實體代碼的正確方式,這:
public class Quote
{
public int Id { get; set; }
[Required, MaxLength(500)]
public string Body { get; set; }
public int Likes { get; set; }
[Required]
public bool isApproved { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
public int AuthorId { get; set; }
public int LanguageId { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
}
public class Author
{
public int Id { get; set; }
[Required, MaxLength(30), MinLength(2)]
public string FirstName { get; set; }
[Required, MaxLength(30), MinLength(2)]
public string LastName { get; set; }
[Required]
public DateTime DOB { get; set; }
public DateTime DOD { get; set; }
[Required, MaxLength(60), MinLength(2)]
public string Occupation { get; set; }
[Required, MaxLength(170), MinLength(5)]
public string WikiLink { get; set; }
public byte[] Image { get; set; }
[Required]
public bool isApproved { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
public virtual ICollection<Quote> Quotes { get; set; }
}
在哪裏我已經給每個引號整數類型標誌着作者和語言或本的ID屬性:
public class Quote
{
public int Id { get; set; }
[Required, MaxLength(500)]
public string Body { get; set; }
public int Likes { get; set; }
[Required]
public bool isApproved { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
public Author Author { get; set; }
public Language Language { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
}
public class Author
{
public int Id { get; set; }
[Required, MaxLength(30), MinLength(2)]
public string FirstName { get; set; }
[Required, MaxLength(30), MinLength(2)]
public string LastName { get; set; }
[Required]
public DateTime DOB { get; set; }
public DateTime DOD { get; set; }
[Required, MaxLength(60), MinLength(2)]
public string Occupation { get; set; }
[Required, MaxLength(170), MinLength(5)]
public string WikiLink { get; set; }
public byte[] Image { get; set; }
[Required]
public bool isApproved { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
public virtual ICollection<Quote> Quotes { get; set; }
}
每個地方都有引用類型作者和類型的語言之一的財產。
我將不勝感激任何幫助。
謝謝。
謝謝拉迪斯拉夫,所以你會推薦我使用?第二個例子?還是第三個你連接我?謝謝 – Ciwan
我喜歡第二個,因爲它更面向對象,但第三個有時更易於使用。 –
第二個。 **非常感謝**。 – Ciwan