简体   繁体   English

如何在Entity Framework Core中使用类似于参考表的表

[英]How to use a table like a reference table in Entity Framework Core

I have three tables, one for storing meta information, on for storing sites and one table for refencing the meta information to the sites. 我有三个表,一个用于存储元信息,一个用于存储站点,另一个表用于将元信息引用到站点。

But I can't seem to figure out how to implement it correctly. 但是我似乎无法弄清楚如何正确实现它。 It would be fairly easy in plain sql, but I want to learn the entity framework core method. 在纯sql中,这将相当容易,但是我想学习实体框架的核心方法。

How would you solve this? 您将如何解决?

IncludeHubEntry; IncludeHubEntry;

public interface IIncludeHubEntry : ISiteBase
{
    string Rel { get; set; }
    int Index { get; set; }
    string Integrity { get; set; }
    string Src { get; set; }
    bool Defer { get; set; }
    bool Async { get; set; }
    string Type { get; set; }
    string Sizes { get; set; }
    bool IsDefault { get; set; }
    CorsCrossoriginTypes Crossorigin { get; set; }
    IncludeEntryTypes EntryType { get; set; }
    int OrderBy { get; set; }
    string Line { get; }
}

IncludeHubIndex.cs (contains the refence between HubEntry and Site): IncludeHubIndex.cs(包含HubEntry和Site之间的引用):

public interface IIncludeHubIndex : ISiteBase
{
    int IncludeHubId { get; set; }
    int SiteId { get; set; }
}

Site.cs: Site.cs:

public interface ISite : ISiteBase
{
    int AppId { get; set; }
    int CultureCollectionId { get; set; }
    string Description { get; set; }
    string WorkName { get; set; }
    CultureCollection Culture { get; set; }
    IEnumerable<IncludeHub> Hub { get; set; }
}

To be clear: I want the IEnumerable Hub to contain elements thats referenced in IncludeHubIndex 要明确:我希望IEnumerable Hub包含在IncludeHubIndex中引用的元素

Several days late, though the general consensus that I've seen so far on doing this, an having had to do this as well is essentially - 迟到了几天,尽管到目前为止,我已经就此达成了普遍共识,但实际上也必须这样做-

Map all 3 classes to their table, with the middle being along the lines of 将所有3个类映射到其表,中间是沿着

public interface IIncludeHubIndex : ISiteBase
{
    IIncludeHubEntry IncludeHub { get; set; }
    ISite Site { get; set; }
}

and then essentially, the two sides of the join both contain a list is the middle object, its really not ideal and use of Nhibernate as opposed to EF Core avoids this issue, though this seems to be a lacking feature of EF Core currently - though correct me if im wrong. 然后从本质上讲,联接的两侧都包含一个列表,是中间对象,它实际上并不理想,并且使用Nhibernate而不是EF Core可以避免此问题,尽管这似乎是EF Core当前缺少的功能-尽管如果我错了纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM