草庐IT

include_path

全部标签

c# - Entity Framework 中多个 "Include"-s 的最佳实践是什么?

假设我们在数据模型中有四个实体:Categories、Books、Authors和BookPages。还假设Categories-Books、Books-Authors和Books-BookPages关系是一对多的。如果从数据库中检索类别实体实例——包括“Books”、“Books.BookPages”和“Books.Authors”——这将成为一个严重的性能问题。此外,不包括它们将导致“对象引用未设置为对象的实例”异常。使用多个Include方法调用的最佳实践是什么?编写单个方法GetCategoryById并将所有项目包含在其中(性能问题)编写单个方法GetCategoryById

c# - 在 Entity Framework 中使用 include 语句时选择特定列

当我需要分层(父子)关系时,我通常在我的EF查询中使用Include语句。例子:DbContext.Customers.Include("Projects");这很好,但是Customers和Projects实体总是会带回所有列。我知道下面的查询将返回父表中的特定列,但我也试图仅返回子表中的特定列。如果我在Projects上使用intellisense,它显然是一个集合,不会提供特定的属性供选择。fromcinCustomersletProjects=c.Projects.Where(p=>p.Notes!=null)whereProjects.Any()selectnew{c.Use

c# - 在 Directory.GetFiles 中使用通配符时出现 "Illegal characters in path"错误

我有一个包含多个包含.doc文件的子目录的目录。示例:C:\Users\user\Documents\testenviroment\Released\test0.docC:\Users\user\Documents\testenviroment\Debug\test1.docC:\Users\user\Documents1\testenviroment\Debug\test2.docC:\Users\user\Documents1\testenviroment\Released\test20.doc我想获取所有Debug文件夹下的所有test*.doc文件。我试过:string[]fi

c# - T4 模板错误 : loading the include file ef. utility.cs.ttinclude 返回了 null 或空字符串

我已经覆盖了Controller生成T4模板(ControllerWithContext.tt),如here所述.我想利用在POCO模型生成器T4模板中使用的EF.utility.CS.ttinclude中的代码帮助实用程序。因此,我将以下行从我的Model.tt复制到我的ControllerWithContext.tt。但是,当我尝试添加Controller时,我收到了错误消息Loadingtheincludefile'EF.utility.CS.ttinclude'returnedanulloremptystring根据MSDNdocumentation,这个错误是因为包含的文件是

c# - LINQ To Entities Include + Where 方法

我有NxN表,想象一下:User(id,...)地址(id,...)UserAddresses包含用户和地址的外键。据我所知,EntityFramework用户创建的实体包含一个UserAddresses集合。Address包含UserAddresses的集合,一个特定的UserAddress包含对User和一个Address的引用。现在我想通过linq进行下一个查询。对于特定的用户ID,仅获取启用标志设置为true的userAddresses。对于特定的用户ID,userAddresses可以包含多个条目,但仅为该特定用户设置一个。我可以做的查询是:context.User.Incl

c# - asp.net 中 ./, ../, ../../, ~/on file path(URL) 之间的区别

我有一个脚本文件。看到路径是~/Script。但是,如果我输入../../而不是~/,该过程也同样有效。我的网站URL如:https://sample.com/Scripts/angular.js如果我在Scripts之前输入../../,那么它会自动更改以前的URL(https://sample.com/Scripts/angular.js).Whatistheurlprocess?Andhowcanitsautomaticallychanged?andpleasetellabouttheDifferentbetween./,../,../../,~/,/Scripts,Script

c# - 我的 EventWaitHandle 说 "Access to the path is denied",但不是

快速总结我现在所知道的我有一个EventWaitHandle我创建然后关闭。当我尝试使用重新创建它时thisctor,会抛出“访问路径...被拒绝”异常。这种异常很少见,大多数时候它只是重新创建了EventWaitHandle正好。通过下面(由我)发布的答案,我可以成功调用EventWaitHandle.OpenExisting并在抛出异常的情况下继续,但是,EventWaitHandle的构造函数应该为我做这件事,对吗?这不就是outparameter,createdNew是为了?初始问题我在同一台服务器上有以下架构、Windows服务和Web服务。Web服务通过打开和设置Windo

c# - Entity Framework 核心 .Include() 问题

一直在尝试使用efcore并遇到include语句的问题。对于这段代码,我得到了2家公司,这是我所期望的。publicIEnumerableGetAllCompanies(HsDbContextdb){varc=db.Company;returnc;}返回[{"id":1,"companyName":"new","admins":null,"employees":null,"courses":null},{"id":2,"companyName":"TestCompany","admins":null,"employees":null,"courses":null}]如您所见,有2家公

c# - "Could not find a part of the path"错误信息

我正在用C#编程,想从闪存盘复制一个文件夹和子文件夹以启动。这是我的代码:privatevoidcopyBat(){try{stringsource_dir="E:\\Debug\\VipBat";stringdestination_dir="C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\StartMenu\\Programs\\Startup";if(!System.IO.Directory.Exists(destination_dir)){System.IO.Directory.CreateDirectory(destin

c# - 在 Entity Framework 查询中过滤 "Includes"表

这是用于.NET3.5的EntityFramework:我需要查询一个表并包含一对多关系的“多”表的集合。我正在尝试将该集合作为查询的一部分进行过滤-我是EntityFramework的新手,而且我在弄清楚它时遇到了麻烦。简化示例:Author有Books,而Book有一个IsFiction列。我想要一个过滤后的作者列表,以及所有小说书籍。没有过滤器,很简单:varq=fromaindb.Authors.Include("Books")wherea.BirthYear>1900selecta;我可以事后过滤,比如:varfictionBooks=a.Books.Where(b=>b.I