[英]entity framework unidirectional association from one to many
I have an Account class which will be used to indicate who is responsible for a certain entity. 我有一个Account类,该类将用于指示谁负责某个实体。 There will be many entities where this will be used, so I don't want to pollute my Account class with all these collections 将有很多实体将被使用,所以我不想用所有这些集合来污染我的Account类。
public class Account
{
public Guid Id{get; set;}
public Guid Name{get; set;}
...
public class EntityConfiguration : EntityConfigurationBase<Account>
{
public EntityConfiguration()
{
// I do not want these!
HasMany(a => a.As)
.WithOptional(x => x.Account)
.HasForeignKey(x =>x.AccountKey);
}
}
}
}
public class A
{
public Guid Id {get; set;}
public Account Account{get; set;}
// FK-Nav property
public Guid AccountKey{get;set;}
public class EntityConfiguration : EntityConfigurationBase<A>
{
public EntityConfiguration()
{
// what should go here to specify the association to Account?
????
}
}
}
public class B
{
public Guid Id {get; set;}
public Account Account{get; set;}
// FK-Nav property
public Guid AccountKey{get;set;}
public class EntityConfiguration : EntityConfigurationBase<B>
{
public EntityConfiguration()
{
// what should go here to specify the association to Account?
????
}
}
}
etc.
public class A
{
public Guid Id {get; set;}
public Account Account{get; set;}
// FK-Nav property
public Guid AccountKey{get;set;}
public class EntityConfiguration : EntityConfigurationBase<A>
{
public EntityConfiguration()
{
HasOptional(x => x.Account).HasMany().HasForeignKey(x=>x.AccountKey);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.