开发者

Linq to Entity get a Date from DateTime

开发者 https://www.devze.com 2023-01-05 16:36 出处:网络
var islemList = (from isl in entities.Islemler where (isl.KayitTarihi.Date >= dbas && isl.KayitTarihi.Value.Date <=dbit) select isl);

var islemList = (from isl in entities.Islemler where (isl.KayitTarihi.Date >= dbas && isl.KayitTarihi.Value.Date <= dbit) select isl);

It gives error: date is not supported in LINQ to Entities... How can 开发者_运维问答i get date in linq.


Use EntityFunctions.TruncateTime.


if KayitTarihi is a date column in DB (and dbas and dbit are DateTime), use:

var islemList = (from isl in entities.Islemler where (isl.KayitTarihi >= dbas && isl.KayitTarihi <= dbit) select isl);


The .Date property is not supported in Linq to Entities (though it may be supported in other implementations of Linq).

I realize that you only want to compare the dates, but there is no real problem with comparing the datetimes if the dbas and dbit values are datetimes with time 00:00:00. You might have to offset the dates or use other inequality checks to get the proper interval but the comparison will work as you intend.

I would personally go with Jandek's solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号