【c# – EF连接5个大表 – Include()方法优化】教程文章相关的互联网学习教程文章

C#-实体框架-Include()加载所有儿童属性,甚至虚拟属性【代码】

我正在尝试使用Entity Framework-Code First构建模型,在该模型中,我使用具有多对多关系的“考试”类和“主题”类.“考试”包含“主题”(主题)的列表.“主题”包含“考试”(考试)的列表. “考试”和“主题”都是虚拟属性. 当我使用context.Exams.Include(“ Subjects”).ToList();时,我会获得所有考试以及与每个考试相关的所有科目,这是可以的.问题是我还参加了与这些科目有关的所有考试. 结果: >考试1 >主题1 >考试3>考试4 >主题2...

c# – ScriptManager.RegisterClientScriptInclude之后的Javascript对象“未定义”错误【代码】

我有一个外部js文件,基本上是一个js对象.我正在使用ScriptManager.RegisterClientScriptInclude方法在页面上包含该文件,之后我使用ScriptManager.RegisterClientScriptBlock方法来调用js对象的方法,但是得到了’DynamicLoadingPanel未定义’的js错误.我知道方法调用在aspx页面中有效时会起作用,但我认为我在ScriptManager注册脚本块时遇到错误原因.我目前在Page_Load事件中有Registers,下面是我的代码.有人可以帮我理解这里发生了什...

c#include指令中使用..(点点)是否合法?

那里.正如标题所说.使用#include“test.h”是合法的.使用#include“test / test.h”也是合法的.但使用#include“../ test.h”是否合法? 例如,#pragma once几乎在每个编译器中都是合法的.但这不是C的标准. 我找不到任何说“保证”是父目录含义的文件.谁能帮我?解决方法:C标准在2.8/ 1中说:Header name preprocessing tokens shall only appear within a #includepreprocessing directive (16.2). The sequences in both forms of...

c# – Include()ThenInclude()在Table Per Hierarchy策略中抛出“Sequence包含多个匹配元素”异常【代码】

我正在使用Entity Framework 7和代码优先,我有一个涉及3个级别的父子关系的模型: >公司有公司>公司属于公司并拥有工厂>工厂属于一家公司 由于这3个实体共享很多共同点,因此它们都从一个抽象的BaseOrganization实体继承. 当我试图列出所有工厂,包括他们的母公司,然后包括他们的母公司时,我有这两种不同的情况: >不将BaseOrganization包含到上下文中,代码优先创建三个表(对应于Table-Per-Concrete-Type或TPC模式). Include()和Then...

使用多个Include()与嵌套的Select()时的c# – EntityCommandExecutionException【代码】

我正在使用MySQL的实体框架.假设我有以下实体: >国家 >州 >城市 >车>建筑 为了热切地包括汽车,我可以使用以下内容:context.Countries.Include(c => c.States.Select(s => s.Cities.Select(ci => ci.Cars))).ToList();同样,要包括一直到建筑物,我可以使用:context.Countries.Include(c => c.States.Select(s => s.Cities.Select(ci => ci.Buildings))).ToList();他们都工作得很好.现在,我想将这两者结合起来,以包括汽车和建筑物,...

c# – 通过Linq Include订购【代码】

我与两个实体有一个多关系:Order: int OrderId string OrderNumber ...OrderItem: int ItemId int sequence ...Product: int ProductId string ProductNameProductType: int ProductTypeid string Title一个订单具有多个OrderItem,每个OrderItem都有一个产品,每个产品都有一个ProductType. 我想写一个Linq,它返回所有订单及其商品,Product,ProductType和商品按顺序字段排序.如何编写查询,如下面的查询? 在Order by with Linq的帮...

c# – EF连接5个大表 – Include()方法优化【代码】

我有以下数据库结构(EDMX模型):public class Company {public Guid Id { get; set; }public virtual ICollection<Location> Locations { get; set; }// ... 15 more columns }public class Location { public Guid Id { get; set; }public virtual Company Company { get; set; }public Guid CompanyId { get; set; }public virtual ICollection<ReportA> ReportsA { get; set; }public virtual ICollection<ReportB> ReportsB ...

c# – IncludeExceptionDetailInFaults表现不佳【代码】

我有这个简单的测试项目只是为了测试IncludeExceptionDetailInFaults行为.public class Service1 : IService1{public string GetData(int value){throw new InvalidCastException("test");return string.Format("You entered: {0}", value);}}[ServiceContract]public interface IService1{[OperationContract]string GetData(int value);}在服务的app.config中,我将其设置为true<serviceDebug includeExceptionDetailInFaults="Tr...

c# – 在实体框架中使用Include方法时如何获得特定的行数?【代码】

我有帖子和评论表.我可以通过这个获得帖子和评论:List<Posts> posts = db.Posts.Include("Comments").ToList();上面的代码返回每个帖子的所有评论.我想要两件事: >获得每篇文章的5条评论.>获取每篇文章的评论总数,同时每篇文章只收到5条评论.解决方法:假设您有这样的Post DTO / View模型/ POCOpublic class PostDto {public string Title{ set; get; }public int Id { set; get; } public List<PostDto> Comments { set; get; }...

手动输入sql即可映射到c#对象,就像.Include(“”)方法一样【代码】

为了简单起见,这里是示例模型.我的模型由一个老师和很多学生组成.public class Teacher{public int Id { get; set; }public string Name { get; set; }public List<Student> Students { get; set; }public Teacher(){Students = new List<Student>();}}public class Student{public int Id { get; set; }public int TeacherId { get; set; }[ForeignKey("TeacherId")]public Teacher Teacher { get; set; }public string Name { ge...

CodeGo.net> .include方法是否在LINQ中命中数据库?【代码】

我正在测试下面的Linq查询.我正在检查日志以查看是否有数据库命中:var productEntities = _context.Set<Product>().Include(p => p.OrderItems).Include(p => p.OrderItems.Select(oi => oi.Order)).Include(p => p.OrderItems.Select(oi => oi.Order.Client));Console.WriteLine(productEntities.Count());无论我是否注释掉对Count()的调用,日志都会显示以下相同输出:06001 SELECT Count(*) FROM INFORMATION_SCHEMA.TABLES AS ...