serkan
serkan

Reputation: 109

Linq to Entity get a Date from DateTime

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.

Upvotes: 10

Views: 8987

Answers (3)

Stephen Cleary
Stephen Cleary

Reputation: 457472

Use EntityFunctions.TruncateTime.

Upvotes: 30

Johan Str&#246;mhielm
Johan Str&#246;mhielm

Reputation: 307

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.

Upvotes: -2

Jaroslav Jandek
Jaroslav Jandek

Reputation: 9563

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);

Upvotes: 1

Related Questions