简体   繁体   English

实体框架在哪里像C#

[英]Entity framework where and like c#

I want to convert this query to entity framework query in c# 我想将此查询转换为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(): 如果要确保使用服务器中的日期,请使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM