Back to directory
Keywords, such as trim, substring, and totaldays, cannot appear in the query statement of LINQ to entity. net keywords are not supported in EF queries. The reason may be to better improve the query performance. After all, good performance depends on your program standards, with a strict standard, a good program can be designed.
Today, we will mainly talk about a backdoor left by EF for the date method. <backdoor> this word should be known in Chinese society. As the name suggests, it is to go against the principle, your principles are useless to me, haha! This is sometimes useful, because under the principle of big, it is very likely that some requirements cannot be implemented. In this case, a backdoor is needed!
The following categories in EF:
System. Data. Objects. sqlclient. sqlfunctions
Let's take an example. This example involves a time-based query.
public System.Linq.Expressions.Expression<Func<Classroom_Live, bool>> SatisfiedBy() { Specification<Classroom_Live> spec = new TrueSpecification<Classroom_Live>(); if (_status.HasValue) { if (_status.Value == 0) spec &= new DirectSpecification<Classroom_Live>(o => (o.Status & (int)Status.AuditNotPass) > 0 || (o.Status & (int)Status.Auditing) > 0 || DateTime.Now < o.BeginTime); else if (_status == 1) spec &= new DirectSpecification<Classroom_Live>(o => (o.Status & (int)Status.AuditPass) > 0 && System.Data.Objects.SqlClient.SqlFunctions.DateDiff("mi", DateTime.Now, o.BeginTime) < o.Minutes); else spec &= new DirectSpecification<Classroom_Live>(o => (o.Status & (int)Status.AuditPass) > 0 && System.Data.Objects.SqlClient.SqlFunctions.DateDiff("mi", DateTime.Now, o.BeginTime) > o.Minutes); } return spec.SatisfiedBy(); }
Back to directory