I have a method which gets the whole data from a View inside my database:
public IQueryable<vw_FullWebIgnoringApprovalStatus> GetAllFullWebIgnoringApprovalStatus()
{
IQueryable<vw_FullWebIgnoringApprovalStatus> query =
Context.vw_FullWebIgnoringApprovalStatus;
return query;
}
When I execute the following method, it immediately executes the query which it shouldn’t:
var model = _repo.GetAllFullWebIgnoringApprovalStatus()
.Where(x =>
(!reid.HasValue && !destid.HasValue && !coid.HasValue) ||
(reid.HasValue && x.Reid == reid.Value) ||
(destid.HasValue && x.Destid == destid.Value) ||
(coid.HasValue && x.Coid == coid.Value)
);
It should have lazy loaded the query and it didn’t. Is it related to view? I am using EntityFramework.4.3.1.
I don’t believe that HasValue is recognized by LINQ to Entities beause there is no way to convert that into SQL. Therefore I think in this case, L2E has to execute the query before it can evaluate HasValue. I haven’t seen this particular behavior before. I thk you need to find another way to express your nullability test. And i’d be interested to see the SQL.
Here’s one interesting idea:
http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/56484ed7-9664-44f4-84a0-69da3901c817
There are all kind of weird behaviors with LINQ around nullables so you have to really pay attention to the results -> http://msdn.microsoft.com/en-us/library/bb738687.aspx
hth
julie