I want to convert this query to entity framework query in c#
Select id
From cachieroperation
Where activation_start < GETDATE() AND activation_end > GETDATE()
AND last_used+'0:8:0'< GETDATE()
AND skipass_number like 'DA3C12DC2186018220%'
var now = DateTime.Now;
var query = from a in cachieroperation
where a.activation_start < now && a.activation_end > now
&& a.last_used < now.AddMinutes(-8) && a.skipass_number.Contains('DA3C12DC2186018220')
select id
If you want to be sure to use the date in the server, use SqlFunctions.GetDate():
var result = from co in context.CachierOperations
where co.ActivationStart < SqlFunctions.GetDate() &&
co.ActivationEnd > SqlFunctions.GetDate() &&
co.LastUsed.AddMinutes(8) < SqlFunctions.GetDate() &&
co.SkiPassNumber.Contains("DA3C12DC2186018220")
select co.Id;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.