.net - Multiple LinqToSQL queries and performance -


Does something like this affect poor performance?

  var myQuery = Select from C from customer C; Var filter1 = myQuery in c where c.ID & gt; 2 Select c; MyQuery = filter1; Var filter2 = c in myQuery where c.Name.Contains ("r") select c; MyQuery = filter2;  

When I do this it only takes the actual query to the end, not every "var ..." Everything starts to form just one query till that point, so it seems that it is ok and keeping all filters in 1 query does not have too much performance differences. Am I wrong and it's actually running many questions against the database?

I am trying to find a good way to create queries based on user input so they can filter on different criteria. I am not very worried about performance, as long as it does not take much time to do it.

I also received a post about the dynamic link library, but it seems that it seems that there is not much difference from doing so.

I will consider using extension methods to dynamically create queries. I think this will really do for you. And, yes, the query is not actually evaluated unless the operation is done, resulting in the combination of them, it is not necessary that there are no more trips to the database.

  var query = db.Customers; If (selectID.HasValue) {query = query.Where (c => c.id> selectID.Value); } If (! String.isnaleourecti (name filter)) {query = query.Where (c => c.Name.Contains (nameFilter)); } Foreach (query in customer) // Now the query is made {...}  

Comments