How to use a table like a reference table in Entity Framework Core

c# entity-framework entity-framework-core

Question

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

1
0
7/28/2018 6:16:48 AM

Popular Answer

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.

0
8/1/2018 8:56:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow