[英]Using Group By on Date Time field - Linq query
I am trying to do a group depending on the DateTime field from the SQLServer Database using Linq query. 我试图根据使用Linq查询的SQLServer数据库中的DateTime字段进行分组。 Below is what I am trying
以下是我正在尝试的
var result = _context.sRProject
.Where(x => x.r_Project == rep)
.GroupBy(x => new { x.s_Date }).ToList();
return result;
Here s_Date is the DateTime field within the DB. s_Date是数据库中的DateTime字段。 I get the below error on the result like
我得到以下关于结果的错误
Cannot implicitly convert type 'System.Collections.Generic.List, Model.sRProject>>' to 'System.Collections.Generic.List'
无法将类型'System.Collections.Generic.List,Model.sRProject >>隐式转换为'System.Collections.Generic.List'
I have in the model class like 我在模型课上有
public class sRProject : IsRProject
{
public DateTime? s_Date { get; set; }
public string delivery { get; set; }
public DateTime? delDate { get; set; }
public string po { get; set; }
public string so { get; set; }
public string r_Project { get; set; }
}
The SQL query I am trying to achieve is like below 我试图实现的SQL查询如下
SELECT [s_Date],[delivery],[delDate],[po],[so],[r_Project]
FROM [sDev].[dbo].[PrjDetails]
where [r_Project] = @rep
group by [s_Date],[delivery],[delDate],[po],[so],[r_Project]
What am I missing here? 我在这里想念什么?
Frame a LINQ query like below: 框架如下所示的LINQ查询:
var result = _context.sRProject
.Where(x => x.r_Project == rep)
.GroupBy(x => new { x.s_Date }).Select(x=>new sRProject{s_Date =x.Key.s_Date, delivery =x.Key.delivery, delDate=x.Key.delDate, po =x.Key.po, so =x.Key.so, r_Project=x.Key.r_Project }).ToList();
return result;
Return type of your method should be sRProject 方法的返回类型应为sRProject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.