InversePropertyAttribute , .
(, , , GameModel) ICollection<T>, T . UserModel.Id int, .
, GameModel.Creator UserModel.Games, ICollection<GameModel> . , EF ( GameModel.Creator , UserModel.Games , , ICollection<T> T , ). , EF work-all-out-by-yourself-magic , InversePropertyAttribute.
, :
class SomePrettyImportantStuff {
[Key]
public int ID { get; set; }
public int OtherId1 { get; set; }
public int OtherId2 { get; set; }
[ForeignKey("OtherId1")]
public virtual OtherImportantStuff Nav1 { get; set; }
[ForeignKey("OtherId2")]
public virtual OtherImportantStuff Nav2 { get; set; }
}
class OtherImportantStuff {
[Key]
public int ID { get; set; }
public virtual ICollection<SomePrettyImportantStuff> SoldStuff { get; set; }
public virtual ICollection<SomePrettyImportantStuff> BoughtStuff { get; set; }
}
EF , 2 FK SomePrettyImportantStuff OtherImportantStuff Id1 Id2, , , .
:
, OnModelCreating , , :
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.Entity<CityModel>().HasMany(c => c.Users).WithRequired(u => u.City)
.HasForeignKey(u => u.CityId).WillCascadeOnDelete(value: false);
base.OnModelCreating(builder);
}