Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在实体框架核心中使用类似于引用表的表_C#_Entity Framework_Entity Framework Core - Fatal编程技术网

C# 如何在实体框架核心中使用类似于引用表的表

C# 如何在实体框架核心中使用类似于引用表的表,c#,entity-framework,entity-framework-core,C#,Entity Framework,Entity Framework Core,我有三个表,一个用于存储元信息,一个用于存储站点,另一个用于将元信息引用到站点 但我似乎不知道如何正确地实现它。在普通sql中这相当容易,但我想学习实体框架核心方法 你将如何解决这个问题 包含子条目 public interface IIncludeHubEntry : ISiteBase { string Rel { get; set; } int Index { get; set; } string Integrity { get; set; } string

我有三个表,一个用于存储元信息,一个用于存储站点,另一个用于将元信息引用到站点

但我似乎不知道如何正确地实现它。在普通sql中这相当容易,但我想学习实体框架核心方法

你将如何解决这个问题

包含子条目

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; }
}
包含hubindex.cs(包含hubench和站点之间的参考):

public interface IIncludeHubIndex : ISiteBase
{
    int IncludeHubId { get; set; }
    int SiteId { get; set; }
}
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; }
}
Site.cs:

public interface IIncludeHubIndex : ISiteBase
{
    int IncludeHubId { get; set; }
    int SiteId { get; set; }
}
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; }
}
公共接口ISite:ISiteBase
{
int-AppId{get;set;}
int CultureCollectionId{get;set;}
字符串说明{get;set;}
字符串工作名{get;set;}
CultureCollection区域性{get;set;}
IEnumerable集线器{get;set;}
}
需要明确的是:我希望IEnumerable中心包含 IncludeHubIndex中引用的元素


晚了几天,虽然我已经看到了关于做这件事的普遍共识,但一个不得不做这件事的人基本上是-

将所有3个类映射到它们的表中,中间沿

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

然后本质上,连接的两边都包含一个列表,这是中间对象,它真的不理想,使用Nhibernate而不是EF Core可以避免这个问题,尽管这似乎是EF Core目前缺乏的特性-尽管如果我错了请纠正我。

等等,我们可以使用接口代替类来定义模型?EF可以直接使用
IEnumerable
而不是
ICollection
-您将如何向关系中添加项?撇开我愚蠢的问题不谈,我相信在创建上下文时,您需要使用注释或linq定义来双向定义关系(ISite具有到IIIncludeHubIndex的导航,反之亦然)。接口在实体框架核心中没有使用,它们只是用来描述DataTables如果您(认为)您知道数据库结构,然后一个选项是首先手动创建数据库,然后使用Scaffold DbContext对其进行反向工程。一旦你能看到EF是如何做到的,那么它就变得更容易调整,等等。看看这应该是可行的,不是吗?除此之外,他们如何重新找到实现类似场景的方法