I'm trying to reproduce the following SQL query in LINQ:
select *
from dbo.events_log
where std_datetimeseq < '2014011523:49:00001'
and logname in ('S', 'D', 'O')
and std_datetimeseq = (
select min(std_datetimeseq)
from dbo.events_log
where std_datetimeseq < '2014011523:49:00001'
and logname in ('S', 'D', 'O'))
This is what I have:
from e in _context.EventLogs
where e.std_datetimeseq.CompareTo(stdDateTimeSeq) < 0
&& eventMessage.Content.EquipToSearch.Contains(e.logname)
&& e.std_datetimeseq.CompareTo(
((from e2 in _context.EventLogs
where e2.std_datetimeseq.CompareTo(stdDateTimeSeq) < 0
&& eventMessage.Content.EquipToSearch.Contains(e2.logname)
select e2).Min().std_datetimeseq)) == 0
select e
I keep getting this exception:
{"The specified method 'MyEntityModel.EventLog Min[EventLog](System.Linq.IQueryable`1[HDSREntityDataModelNS.EventLog])'
on the type 'System.Linq.Queryable' cannot be translated into
a LINQ to Entities store expression because no overload matches the passed arguments."}
I have no idea what's wrong.
eventMessage.Content.EquipToSearch is a List with "S", "D", "O" in it. The LINQ is going against entity framework.
Thanks
select e2).Min().std_datetimeseq)) == 0toselect e2.std_datetimeseq).Min())) == 0.CompareToto compare the dates, just use the less than and equality operators.