简体   繁体   中英

How can I optimize this linq query?

I have a table EmployeDetails . I am deleting rows from this table by first getting a list of the employees. Using remove range function of linq but it's taking too much time I have 10000 records in the table.

_dbRepository.Write( ctx => ctx.EmployeDetails.RemoveRange(
         ctx.EmployeDetails.Where(
             v => !v.LastLogin.HasValue || DbFunctions.DiffDays(DbFunctions.CreateDateTime(v.LastUpdate.Value.Year, v.LastUpdate.Value.Month, v.LastUpdate.Value.Day, 0, 0, 0), today) > 0)));
};

Try this:

_dbRepository.Write( ctx =>       ctx.Database.ExecuteSqlCommand(@"
delete from EmployeDetails
where LastLogin is null
or CONVERT(date, LastUpdate) > {0}", today));

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.

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