2014-11-08 17 views
-2

我使用實體框架,並有一些類哪些屬性應該被用於正確assotiation

public class Lot 
{ 
    public int LotId { get; set; } 
    public string Description { get; set; } 
    public virtual Product Product { get; set; } 
    public virtual ApplicationUser Owner { get; set; } 
    public virtual ApplicationUser CurrentCustomer { get; set; } 
    public virtual ICollection<ApplicationUser> AllCustomers { get; set; } 
    public virtual AuctionDates AuctionDates { get; set; } 
    public virtual AuctionPrices AuctionPrices { get; set; } 
    public virtual State State { get; set; } 
    public virtual ProductImages Images { get; set; } 
} 

public class ApplicationUser : IdentityUser 
{ 
    [Required] 
    public virtual UserInfo UserInfo { get; set; } 
    public virtual ICollection<Lot> SelledLots { get; set; } 
    public virtual ICollection<Lot> BuyedLots { get; set; } 
    public virtual ICollection<Lot> ParticipatedLots { get; set; } 
} 

,問題是我怎麼可以設置誰賣映射的用戶配置業主(Lot)中的批次(ApplicationUser),在當前客戶(Lot)中購買批次(ApplicationUser)等等。非常感謝。

回答

0

我終於找到了答案。在這種情況下,應該使用數據註釋InverseProperty。 https://www.safaribooksonline.com/library/view/programming-entity-framework/9781449317867/ch04s03.html

public class Lot 
{ 
    public int LotId { get; set; } 
    public string Description { get; set; } 
    public virtual Product Product { get; set; } 
    [InverseProperty("SelledLots")] 
    public virtual ApplicationUser Owner { get; set; } 
    [InverseProperty("BuyedLots")] 
    public virtual ApplicationUser CurrentCustomer { get; set; } 
    [InverseProperty("ParticipatedLots")] 
    public virtual ICollection<ApplicationUser> AllCustomers { get; set; } 
    public virtual AuctionDates AuctionDates { get; set; } 
    public virtual AuctionPrices AuctionPrices { get; set; } 
    public virtual State State { get; set; } 
    public virtual ProductImages Images { get; set; } 
} 
+0

把一些代碼請... – 2014-11-08 19:59:19

相關問題