简体   繁体   中英

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.

How would you solve this?

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):

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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