gpt4 book ai didi

c# - Linq to entities 不知道 .Date 运算符是什么

转载 作者:行者123 更新时间:2023-11-29 04:51:41 25 4
gpt4 key购买 nike

我收到一条错误消息,说 linq to entities 不知道以下查询中的 .Date 运算符:

var data = from p in page_loads
join f in sites
on p.site_id equals f.id
join tr in test_runs
on p.test_run_id equals tr.id
where f.id == 17
group p by p.created_at.Date into g
select new { time = g.Average(t => t.time), created_at = g.Key };

注意 created_at 在数据库中是NOT NULL。我指出这一点是因为我知道 created_at 不可为 null,并且 linq to entities 会有问题。但我不知道如何解决这个问题。

编辑:

[EdmScalarProperty(EntityKeyProperty = false, IsNullable = false)]
[DataMember]
public DateTime created_at { get; set; }

最佳答案

听起来你可能想要 SqlFunctions.DatePart :

group p by SqlFunctions.DatePart("day", p.created_at) into g

关于c# - Linq to entities 不知道 .Date 运算符是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11126371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com