- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
x.ReportDate == new Dat-6ren">
我正在运行一个类似 linq 的查询
dbEntity.Where(x => x.FundType== "E")
.Where(x => x.ReportDate == new DateTime(2014,10,23))
.GroupBy(x => x.ReportDate)
.Select(groupedDate => new CategorySourceData
{
ReportDate = groupedDate.Key,
TotalFlow = groupedDate.Sum(x => x.Flow)
}
.ToList();
我希望它给我与此查询相同的结果以及类似的运行时间
select ReportDate,
sum(flow)
from vwDailyFundFlowDetail
where FundType = 'E'
group by ReportDate
Ef 生成返回正确数据的查询。但是,我的手写查询在我的测试集上花费了大约 13 秒,而 ef 生成的查询在同一测试集上花费了 24 秒。
ef 查询看起来像
exec sp_executesql N'SELECT
1 AS [C1],
[GroupBy1].[K1] AS [ReportDate],
CAST( [GroupBy1].[A1] AS real) AS [C2]
FROM ( SELECT
[Extent1].[ReportDate] AS [K1],
SUM([Extent1].[Flow]) AS [A1]
FROM (SELECT
[vwDailyFundFlowDetail].[HFundId] AS [HFundId],
[vwDailyFundFlowDetail].[ReportDate] AS [ReportDate],
[vwDailyFundFlowDetail].[Flow] AS [Flow],
[vwDailyFundFlowDetail].[ForexChange] AS [ForexChange],
[vwDailyFundFlowDetail].[AssetsEnd] AS [AssetsEnd],
[vwDailyFundFlowDetail].[ShareID] AS [ShareID],
[vwDailyFundFlowDetail].[ShareClass] AS [ShareClass],
[vwDailyFundFlowDetail].[ISIN] AS [ISIN],
[vwDailyFundFlowDetail].[CUSIP] AS [CUSIP],
[vwDailyFundFlowDetail].[Ticker] AS [Ticker],
[vwDailyFundFlowDetail].[AssetsStart] AS [AssetsStart],
[vwDailyFundFlowDetail].[PortfolioChange] AS [PortfolioChange],
[vwDailyFundFlowDetail].[FundName] AS [FundName],
[vwDailyFundFlowDetail].[SSID] AS [SSID],
[vwDailyFundFlowDetail].[Advisor] AS [Advisor],
[vwDailyFundFlowDetail].[GEOID] AS [GEOID],
[vwDailyFundFlowDetail].[FTCID] AS [FTCID],
[vwDailyFundFlowDetail].[BenchIndex] AS [BenchIndex],
[vwDailyFundFlowDetail].[FundType] AS [FundType],
[vwDailyFundFlowDetail].[ETF] AS [ETF],
[vwDailyFundFlowDetail].[Domicile] AS [Domicile],
[vwDailyFundFlowDetail].[GeographicFocus] AS [GeographicFocus],
[vwDailyFundFlowDetail].[Currency] AS [Currency],
[vwDailyFundFlowDetail].[FundDomicile] AS [FundDomicile],
[vwDailyFundFlowDetail].[Manager] AS [Manager],
[vwDailyFundFlowDetail].[FundCurrency] AS [FundCurrency],
[vwDailyFundFlowDetail].[Benchmark] AS [Benchmark],
[vwDailyFundFlowDetail].[FundFocus] AS [FundFocus],
[vwDailyFundFlowDetail].[NetChange] AS [NetChange],
[vwDailyFundFlowDetail].[FundId] AS [FundId],
[vwDailyFundFlowDetail].[InstOrRetail] AS [InstOrRetail],
[vwDailyFundFlowDetail].[Hedge_yn] AS [Hedge_yn],
[vwDailyFundFlowDetail].[SRI_yn] AS [SRI_yn],
[vwDailyFundFlowDetail].[SCID] AS [SCID],
[vwDailyFundFlowDetail].[DistributorId] AS [DistributorId],
[vwDailyFundFlowDetail].[Distributor] AS [Distributor],
[vwDailyFundFlowDetail].[Frontier] AS [Frontier],
[vwDailyFundFlowDetail].[FundCategory] AS [FundCategory],
[vwDailyFundFlowDetail].[Commodity] AS [Commodity],
[vwDailyFundFlowDetail].[CurrId] AS [CurrId],
[vwDailyFundFlowDetail].[Idx] AS [Idx],
[vwDailyFundFlowDetail].[Bear] AS [Bear],
[vwDailyFundFlowDetail].[Dividend] AS [Dividend],
[vwDailyFundFlowDetail].[AbsoluteReturn] AS [AbsoluteReturn],
[vwDailyFundFlowDetail].[Islamic_yn] AS [Islamic_yn],
[vwDailyFundFlowDetail].[Ins] AS [Ins],
[vwDailyFundFlowDetail].[Inf] AS [Inf],
[vwDailyFundFlowDetail].[Silver] AS [Silver],
[vwDailyFundFlowDetail].[Gold] AS [Gold],
[vwDailyFundFlowDetail].[AG] AS [AG],
[vwDailyFundFlowDetail].[Metal] AS [Metal],
[vwDailyFundFlowDetail].[Administrator] AS [Administrator],
[vwDailyFundFlowDetail].[Custodian] AS [Custodian],
[vwDailyFundFlowDetail].[Bear2x] AS [Bear2x],
[vwDailyFundFlowDetail].[Bear3x] AS [Bear3x],
[vwDailyFundFlowDetail].[Leverage1x] AS [Leverage1x],
[vwDailyFundFlowDetail].[Leverage2x] AS [Leverage2x],
[vwDailyFundFlowDetail].[MuniStateId] AS [MuniStateId],
[vwDailyFundFlowDetail].[Leverage3x] AS [Leverage3x],
[vwDailyFundFlowDetail].[Synthetic_ETF] AS [Synthetic_ETF],
[vwDailyFundFlowDetail].[Physical_ETF] AS [Physical_ETF],
[vwDailyFundFlowDetail].[IG] AS [IG],
[vwDailyFundFlowDetail].[EMC] AS [EMC],
[vwDailyFundFlowDetail].[EMS] AS [EMS],
[vwDailyFundFlowDetail].[EMM] AS [EMM],
[vwDailyFundFlowDetail].[MuniState] AS [MuniState],
[vwDailyFundFlowDetail].[FundQualityId] AS [FundQualityId],
[vwDailyFundFlowDetail].[FundDurationId] AS [FundDurationId],
[vwDailyFundFlowDetail].[QualityName] AS [QualityName],
[vwDailyFundFlowDetail].[DurationName] AS [DurationName],
[vwDailyFundFlowDetail].[ClosedEnd] AS [ClosedEnd],
[vwDailyFundFlowDetail].[MLP] AS [MLP],
[vwDailyFundFlowDetail].[ArrivalTime] AS [ArrivalTime],
[vwDailyFundFlowDetail].[ArrivalDayCode] AS [ArrivalDayCode],
[vwDailyFundFlowDetail].[DActivationDate] AS [DActivationDate],
[vwDailyFundFlowDetail].[WActivationDate] AS [WActivationDate],
[vwDailyFundFlowDetail].[MActivationDate] AS [MActivationDate],
[vwDailyFundFlowDetail].[ShareClassCurrency] AS [ShareClassCurrency]
FROM [dbo].[vwDailyFundFlowDetail] AS [vwDailyFundFlowDetail]) AS [Extent1]
WHERE ((@p__linq__0 IS NULL) OR ([Extent1].[FundType] = @p__linq__1) OR (([Extent1].[FundType] IS NULL) AND (@p__linq__1 IS NULL))) AND (0 = (CASE WHEN ( EXISTS (SELECT
1 AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0
)) THEN cast(1 as bit) ELSE cast(0 as bit) END))
GROUP BY [Extent1].[ReportDate]
) AS [GroupBy1]',N'@p__linq__0 nvarchar(4000),@p__linq__1 varchar(8000)',@p__linq__0=N'E',@p__linq__1='E'
where子句所在的部分
AND (0 = (CASE WHEN ( EXISTS (SELECT
1 AS [C1]
FROM ( SELECT 1 AS X ) AS [SingleRowTable1]
WHERE 1 = 0
)) THEN cast(1 as bit) ELSE cast(0 as bit) END))
似乎是主要问题。据我所知,case 语句始终为 0,所以这始终为真。这部分查询的存在正在改变执行计划的一部分
如果我从 where 子句中删除 case 语句,那么据我所知,该查询的执行计划和运行时间与我手写的 sql 将变得完全相同。如何阻止 EF 添加 where 子句的这一部分?我在我的 linq 代码中做了什么使 EF 将此添加到查询中?
最佳答案
您需要在 DBContext
上设置 Configuration.UseDatabaseNullSemantics = true;
这将阻止添加的is null
检查
关于c# - 如何阻止 EF 生成无用代码,这有关系吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32125788/
哇,我一直在尝试让一个简单的 Android Twitter 应用程序运行,但这是不可能的。我来自 iOS 背景。我目前正在努力使这些工作: 来自 Marakana 的 MyTwitter 应用程序。
我只花了几个小时调试一个编译器错误,如果编译器的错误消息更有用,我可以立即修复这个错误。 我把它简化为一个简单的例子: template int f(int); template auto g(U
我想调整我的线条(两条)的大小,因为我觉得它们太瘦了。 下面的代码这样做了,但是为 size 创建了一个图例,这是无用的,因为 size 没有可以映射到它的变量。 qplot(date,value,d
如果我这样做 xset dpms 600 3600 7200 ,它在 10 点后使我的屏幕空白 几分钟的不事件。 问题 X11 怎么知道我闲了多久,我怎么才能访问这个 以编程方式空闲时间? 我无法获得
在调查 ConflictError ( see this previous question ) 时,我看到了很多 persistent.mapping.PersistentMapping 冲突。 具
我正在使用 PHP 和 jQuery 创建交互式白板应用程序。创建一个卡片组不是问题,也不是在页面上应用 Canvas 覆盖以便我可以在上面写字。我是一名业余编码员,完全是自学成才。这部分是学习更多的
我是网页设计的自学者,所以我可能会错过一些基础编码。 所以问题是 内容在一行中从右边溢出了 div。 代码如下 HTML
我在将 DRF SessionAuthentication 与定义为 ModelViewSets 的 View 一起使用时遇到问题。 “LoginRequiredMixin”在泛型 View 中工作正
这是我的一段代码:输出看起来像:12、44、55,我需要删除最后一个“,”,我尝试了所有方法。 while ((r = scanf("%d", &v)) > 0){ printf("%
我正在做这样的事情 http://jsfiddle.net/8ErSL/2/ 当您将鼠标悬停在任何文本框 (div) 上时,其中会出现一个小图标。 我想阻止图标的淡入淡出效果在我不小心将鼠标悬停在 d
我使用“wget --mirror [sitename]”启动了一个 wget 镜像,它是工作正常,但意外中断了该过程。 我现在想恢复镜像,但有以下警告: 如果 wget 已经下载了一个文件,我不想下
我有一个包含多个子项的 DOM 元素 (#installations),其中只有一个具有类 .selected。我需要选择此类和其余的前 3 个 (:not(.selected)) 并显示它们 - 目
我是一名优秀的程序员,十分优秀!