C# 哪些属性应用于正确关联
我正在使用实体框架,并且有一些类C# 哪些属性应用于正确关联,c#,entity-framework,C#,Entity Framework,我正在使用实体框架,并且有一些类 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 ApplicationU
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; }
}
及
问题是如何为在OwnerLot中出售LotusApplicationUser、在当前customerLot中购买LotusApplicationUser的映射用户设置配置,等等。非常感谢 我终于找到了答案。在这种情况下,应使用数据注释反向属性
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; }
}
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; }
}