Код: Выделить всё
public class User {
public int UserId { get; set; }
public ICollection Orders { get; set; }
public ICollection Sales { get; set; }
}
public class Listing {
public int ListingId { get; set; }
public int UserId { get; set; }
public User User { get; set; }
}
public class Order {
public int ListingId { get; set; }
public Listing Listing { get; set; }
public int BuyerId { get; set; }
public User Buyer { get; set; }
}
modelBuilder.Entity()
.HasOne(e => e.Buyer)
.WithMany(e => e.Orders)
.HasForeignKey(e => e.BuyerId);
modelBuilder.Entity()
.HasOne(e => e.Listing.User)
.WithMany(e => e.Sales)
.HasForeignKey(e => e.Listing.UserId);
Код: Выделить всё
User.SalesThe code above should explain what I'm trying to do but the
Код: Выделить всё
e.Listing.UserКод: Выделить всё
e.Listing.UserIdI know I can solve the problem by introducing
Код: Выделить всё
SellerIdКод: Выделить всё
SellerКод: Выделить всё
OrderКод: Выделить всё
ListingКод: Выделить всё
Order.Listing.UserIdКод: Выделить всё
Order.Listing.UserIs there a way to configure the relationship without that?
Источник: https://stackoverflow.com/questions/781 ... oreign-key