- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个在 LinqPad 中按预期运行的 Linq 语句(使用 Linq to SQL),但是当我使用 EF 6 将它引入我的 C# 应用程序时,我收到一条错误消息,指出 cd.LogTimestamp.Date(在 GroupBy 语句中)不支持。我正在尝试将 datetime2 值转换为日期值以用于分组目的。
helper.GetDbContext().SiteLog
.Where( sl => sl.SiteId == 3 )
.GroupBy( cd => new { cd.SiteId, cd.LogTimestamp.Date } )
.Select( g => new DailyTraffic()
{
SiteId = g.Key.SiteId,
TrafficDate = g.Key.Date,
NewUsers = g.Count( row => row.IsNewUser ),
ReturningUsers = g.Count( row => row.IsReturningUser ),
TotalUsers = g.Count( row => row.IsNewUser ) + g.Count( row => row.IsReturningUser ),
PageViews = g.Count( row => row.IsPageView )
} )
.OrderBy( g => g.SiteId ).ThenBy( g => g.TrafficDate )
.ToList();
是否有一种首选方法可以将 datetime2
值转换为 EF 6 中的 date
值
最佳答案
使用此 QA (how to use entity framework to group by date not date with time) 作为指南,您需要使用 EntityFunctions
以便您可以直接使用内置的 SQL Server 函数,这当然意味着您的应用程序不会不能立即移植到其他数据库。
.GroupBy( cd => new { cd.SiteId, EntityFunctions.TruncateTime( cd.LogTimestamp ) } )
关于entity-framework - 在 iEF 中将日期时间转换为日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34826228/
我有一个在 LinqPad 中按预期运行的 Linq 语句(使用 Linq to SQL),但是当我使用 EF 6 将它引入我的 C# 应用程序时,我收到一条错误消息,指出 cd.LogTimesta
我用 JavaScript 编写了一个程序,它显示 5 个矩形,一个接一个,延迟约 1 秒。由于 Javascript 中没有像 C 或其他语言那样的静态变量,因此我使用了一个 IIEF,它在变量 d
有人知道是否可以通过 Azure DevOps 任务上传自定义策略吗? 发布管道可能如下所示: 暂存环境 - 从 Git 部署到 IEF,添加后缀 _staging 阻止手动测试的管道 产品环境 -
有人知道是否可以通过 Azure DevOps 任务上传自定义策略吗? 发布管道可能如下所示: 暂存环境 - 从 Git 部署到 IEF,添加后缀 _staging 阻止手动测试的管道 产品环境 -
我在使用 Azure B2C IEF 可用的段落用户输入类型时遇到了一些问题。我想使用 Paragraph 元素,因为它会使本地化变得容易得多。但是,无论我尝试过什么,我都无法让 Paragraph
我正在使用自定义策略调用 REST API 以从数据库获取某些内容并在声明中返回。它工作正常,但我需要扩展该功能以发送额外的错误代码和错误消息,以防发生任何异常。我已经按照要求返回了此类信息(“sta
我是一名优秀的程序员,十分优秀!