我需要使用“转换为日期时间”方法来将日期时间与参考月份和年份进行比较,如下所示。
我知道在sql中提供程序不能翻译Convert.ToDateTime,我需要一个想法来执行这个查询。
更新:在进行转换之前,我不会将查询实体化,因为这显然意味着获取所有记录。
var res = db.Table1
//other tables, and where conditions
.Select(x => new MyObj
{
//...
Imp = x.MyTable.FirstOrDefault(y => y.date_val >= System.Data.Entity.DbFunctions.AddMonths(Convert.ToDateTime("01/" + x.month + "/" + x.year), 1))).Description
})
我知道在sql中提供程序不能翻译Convert.ToDateTime,我需要一个想法来执行这个查询。
更新:在进行转换之前,我不会将查询实体化,因为这显然意味着获取所有记录。
Convert.ToDateTime
无法转换为 T-SQL,Linq to Entities 无法识别它。请参考此答案:http://stackoverflow.com/a/34061692/2946329。 - Salah Akbarix.MyTable.AsEnumerable().FirstOrDefault.......
只是一个想法,还没有在日期转换中测试过。 - SplufMyTable
加载到内存中,这通常是不可取的。 - NetMage