1
我目前面临的问题是,我有一个单一的实体(艺术家),它可以是一个“头条新闻”或“支持行为”多种关系。EF与同一实体的多对多关系
的这些表的的极端简化版本:
+----------------+ +----------------+
| Artist | | Event |
+----------------+ +----------------+
| ArtistId | | EventId |
| ExternalId | | Name |
| Name | | |
+----------------+ +----------------+
正如我引入了两个附加实体来满足这些要求的中间溶液。
+----------------+ +----------------+
| Headliner | | SupportAct |
+----------------+ +----------------+
| ArtistId | | ArtistId |
| EventId | | EventId |
+----------------+ +----------------+
并介绍了下面的代码在事件实体
private ICollection<Headliner> _headliners;
public virtual ICollection<Headliner> Headliners
{
get { return _headliners ?? (_headliners = new Collection<Headliner>()); }
protected set { _headliners = value; }
}
private ICollection<SupportAct> _supportActs;
public virtual ICollection<SupportAct> SupportActs
{
get { return _supportActs ?? (_supportActs = new Collection<SupportAct>()); }
protected set { _supportActs = value; }
}
我试图做到的是一个更精简的解决方案,它看起来是这样的,你会发现下面。
而且代码将被缩减为类似的内容,您将在下面找到。但是,这是不允许的....
private ICollection<Artist> _headliners;
public virtual ICollection<Artist> Headliners
{
get { return _headliners ?? (_headliners = new Collection<Artist>()); }
protected set { _headliners = value; }
}
private ICollection<Artist> _supportActs;
public virtual ICollection<Artist> SupportActs
{
get { return _supportActs ?? (_supportActs = new Collection<Artist>()); }
protected set { _supportActs = value; }
}
高于可行描述类似的东西,因为它会给我的艺术家实体直接访问?
为什么你不能做到只用1结表吧:只需取下
Headliner
和SupportAct
实体,并使用以下? – Sampath