- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
为什么 EF 6 使用以下代码查询数据库中的所有记录?
public virtual List<T> Find(Func<T, bool> where = null)
{
_db.Configuration.LazyLoadingEnabled = false;
if (where == null) throw new NullReferenceException("The 'where' parameter of the Repository.Find() method is null.");
return _dbSet.Where(where).ToList();
}
产生以下输出
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Sequence] AS [Sequence],
[Extent1].[Description] AS [Description],
[Extent1].[Instructions] AS [Instructions],
[Extent1].[WorkCenterOperationId] AS [WorkCenterOperationId],
[Extent1].[JobId] AS [JobId],
[Extent1].[JobAssemblyId] AS [JobAssemblyId],
[Extent1].[RowVersion] AS [RowVersion]
FROM [dbo].[JobOperations] AS [Extent1]
两个问题:
最佳答案
您使用了 Func<T,bool>
而不是 Expression<Func<T,bool>>
因此,您已经(在某处)强制从数据库 Linq-to-Entities 过渡到 Linq-to-Objects。所以它是在内存中处理的。
而且,正如@Marc 指出的那样,一个简单的解决方法可能是:
public virtual List<T> Find(Expression<Func<T, bool>> where = null)
...
但这又取决于调用代码的形式是否可以生成 Func<T,bool>
或 Expression<Func<T,bool>>
(通常,lambda 可以转换为任何一种形式)
关于c# - DbSet<T>.Where(where).ToList() - 为什么 SQL 不包含 where 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23245706/
在 ToList() 中指定具体类型是否有意义? , AsEnumerable()等方法? 威尔.ToList()执行速度比 .ToList() 快? 最佳答案 如果编译器推断出一种类型而您想要指定另
给定在内存中(不是 LINQ to SQL)类列表: List myItems = /*lots and lots of items*/; 我正在使用 GroupBy() 语句对其进行分组: myIt
我对此不是 100%,所以我需要专家的意见。 ConcurrentQueue queue = new ConcurrentQueue(); List listA = queue.ToArray().T
JDK 引入了一个 API Stream.toList() 和 JDK-8180352 。这是我尝试将其性能与现有 Collectors.toList 进行比较的基准测试代码: @BenchmarkM
说到性能,我应该使用 .ToList().Distinct() 还是 .Distinct().ToList() ? 两种扩展方法是否生成相同的 SQL 查询? 看起来第二种方法应该表现更好,但这是真的
当我调用它时: using (var db = new MyDbContext()) { var yy = db.Products.Select(xx => xx.Id); var i
我正在寻找这些 LINQ 表达式的确认/澄清: var context = new SomeCustomDbContext() // LINQ to Entities? var items = co
JDK 16 now includes a toList() method directly on Stream instances。在以前的Java版本中,您始终必须使用collect方法并提供Co
我真的很困惑如何解决这个问题 public bool DeleteVegetationZone(ref Assessment objAssessment, int VegetationZoneIDT
import numpy as np from scipy.sparse import lil_matrix 使用 numpy 我得到 test_mat = (np.ones((4,6))) test
当我有一个 IEnumerable我不知道它是否是一个列表(根据 List ),我必须枚举 IEnumerable以确保我不会枚举那个可枚举项两次(例如循环两次,或类似的事情)。 Resharper
我不知道 LinqQuery.ToList().Distinct() 和 LinqQuery.Distinct().ToList(); 对我来说有什么区别看起来一样。 考虑这个示例代码: List s
给定以下 LINQ 语句,哪个更有效? 一个: public List GetLatestLogEntries() { var logEntries = from entry in db.Lo
我正在尝试使用 Moq 模拟 Entity Framework DbContext,尤其是它的扩展方法 Add()、Tolist() 和 Find()。 我需要 Find() 和 ToList() 方
这个问题在这里已经有了答案: java 8 Collector is not a functional interface, who can tell why? (2 个回答) Java8: Usin
我只是在尝试新的 kotlin 语言。我遇到了生成无限列表的序列。我生成了一个序列并尝试打印前 10 个元素。但是下面的代码没有打印任何东西: fun main(args: Array) {
我们的代码库中都弹出了这两个代码 pandas.DataFrame.columns.values.tolist() pandas.DataFrame.columns.tolist() 这些总是相同的吗
这些 linq 查询有什么区别: Students.Where(x=>x.City == "Lahore").ToList(); Students.ToList().Where(x=>x.City =
我试图通过创建一个存储前 3 个值的单独变量来过滤数组列表。但是,在集合中出现错误。我对此很陌生,所以任何帮助都会很棒! public static ArrayList exerciseDetail(
我看到以下代码: using(var iterator = source.GetEnumerator()) {...} 哪里source是 IEnumerable . 执行上述操作与转换相比有何优势
我是一名优秀的程序员,十分优秀!