I have an object IQueryable that represent some query over my db-model. Now i need to do some validation to that IQeryable and return back the object in that way
private IQuerable<myTableType> ValidateQery ( IQuerable<myTableType> query , string user )
{
return query.Where ( x => db.tblUsers.Where( y => y.User == user && y.Privilege >= x.PrivilegeRequired).Any() )
}
Now what i would like to understand is if the Any() clause is executed immidiatly or if it generate T-SQL that will be merged with previous. I ask that because i wuold avoid to execute a query against the db in that moment.
Edit : Thanks for the advice of 'using' clause, it was a fault that i made now (writing this code example) because i am not able to test code now (i have no visual studio on my machine in this moment) but my problem in general was about that situation.
It's part of the query - it's within a Where
clause.
So no, it won't be executed immediately. Having said that, you appear to be closing the context that the query uses, so I suspect that by the time it is used, it'll be broken...
See more on this question at Stackoverflow