Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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#_Join_Ef Code First - Fatal编程技术网

C# 如何实现实体框架代码优先连接

C# 如何实现实体框架代码优先连接,c#,join,ef-code-first,C#,Join,Ef Code First,我首先开始使用实体框架代码 假设有这样的POCO(最终简化): 和上下文 public MyContext : DbContext { public DbSet<BortStructure> BortStructures { get; set; } public DbSet<Slot> Slots{ get; set; } public DbSet<SystemType> SystemTypes { get; set; } public

我首先开始使用实体框架代码

假设有这样的POCO(最终简化):

和上下文

public MyContext : DbContext
{
   public DbSet<BortStructure> BortStructures { get; set; }
   public DbSet<Slot> Slots{ get; set; }
   public DbSet<SystemType> SystemTypes { get; set; }
   public DbSet<SlotSystemType> SlotSystemTypes { get; set; }
}
但首先使用实体框架代码,我不知道如何做到这一点

如果我使用

var slotSystemTypes = from sl in MyContext.SlotSystemTypes
where sl.Slot.BortStructure.Id = XXXXXX
orderby sl.Slot.Id, sl.SystemType.Id
select sl;
i、 当然,如果BortStructure不包含插槽/未连接任何系统类型的插槽,则将不会收到任何内容

与使用空插槽列表/插槽获取BortStructure不同,每个BortStructure都附带了空的SystemTypes列表,正如我所期望的那样


对于我的数据库配置,是否有任何方法可以使用单一LINQ查询来存档这些内容?

您可以使用
join
操作符示例:

string[] categories = new string[]{  
    "Beverages",   
    "Condiments",   
    "Vegetables",   
    "Dairy Products",   
    "Seafood" };  

List<Product> products = GetProductList(); 

var q = 
    from c in categories 
    join p in products on c equals p.Category 
    select new { Category = c, p.ProductName }; 

foreach (var v in q) 
{ 
    Console.WriteLine(v.ProductName + ": " + v.Category);  
} 
string[]categories=新字符串[]{
“饮料”,
“调味品”,
“蔬菜”,
“乳制品”,
"海鲜";;
List products=GetProductList();
变量q=
从c到类别
在c等于p的范畴上的乘积中加入p
选择新建{Category=c,p.ProductName};
foreach(q中的v值)
{ 
Console.WriteLine(v.ProductName+:“+v.Category);
} 

更多示例请参见:

您可以使用
join
运算符示例:

string[] categories = new string[]{  
    "Beverages",   
    "Condiments",   
    "Vegetables",   
    "Dairy Products",   
    "Seafood" };  

List<Product> products = GetProductList(); 

var q = 
    from c in categories 
    join p in products on c equals p.Category 
    select new { Category = c, p.ProductName }; 

foreach (var v in q) 
{ 
    Console.WriteLine(v.ProductName + ": " + v.Category);  
} 
string[]categories=新字符串[]{
“饮料”,
“调味品”,
“蔬菜”,
“乳制品”,
"海鲜";;
List products=GetProductList();
变量q=
从c到类别
在c等于p的范畴上的乘积中加入p
选择新建{Category=c,p.ProductName};
foreach(q中的v值)
{ 
Console.WriteLine(v.ProductName+:“+v.Category);
} 
更多样本请访问:

string[] categories = new string[]{  
    "Beverages",   
    "Condiments",   
    "Vegetables",   
    "Dairy Products",   
    "Seafood" };  

List<Product> products = GetProductList(); 

var q = 
    from c in categories 
    join p in products on c equals p.Category 
    select new { Category = c, p.ProductName }; 

foreach (var v in q) 
{ 
    Console.WriteLine(v.ProductName + ": " + v.Category);  
}