score:2
Accepted answer
Try refactoring the IsNullOrEmpty condition like this:
return (from r in Repository.Query<Measurement>()
where
(string.IsNullOrEmpty(postalCode)
|| r.Postal.ToLowerInvariant() == postalCode.ToLowerInvariant()
)
&&
(string.IsNullOrEmpty(trait)
|| r.Trait.ToLowerInvariant() == trait.ToLowerInvariant()
)
select r).ToList();
That may cause LINQ to evaluate the IsNullOrEmpty before sending off the query. If not, you could precalculate them manually and put a couple boolean variables in their place.
score:1
Have you tried forcing the deferred execution by calling Repository.Query().ToList()
before the where clauses? I noticed it looks like NHibernate is attempting to convert the string.IsNullOrEmpty()
call into SQL syntax (and failing).
return (from r in Repository.Query<Measurement>().ToList()
where
r.Postal.ToLowerInvariant() ==
(string.IsNullOrEmpty(postalCode)
? r.Postal : postalCode).ToLowerInvariant()
&&
r.Trait.ToLowerInvariant() ==
(string.IsNullOrEmpty(trait)
? r.Trait : trait).ToLowerInvariant()
select r).ToList();
Source: stackoverflow.com
Related Query
- Make Linq to Sql generate T-SQL with ISNULL instead of COALESCE
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- IsNull or Coalesce functionality in LINQ?
- Linq ISNULL functionality
- source code for LINQ 101 samples
- How to get same functionality as ISNULL in LINQ query
- Using LINQ Expressions to Multiple Left Join and use ISNULL Functionality
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- How to detect IsNull / NotNull when building dynamic LINQ expressions?
- Syntax to execute code block inside Linq query?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Best open source LINQ provider
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ WHERE method alters source collection
- Where can I view LINQ source code?
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Left outer join using LINQ -- understanding the code
- How to pass LinQ Expressions from F# to C# code
- How to reuse a linq expression for 'Where' when using multiple source tables
- C# Null coalesce with LINQ
- Avoiding code repetition when using LINQ
More Query from same tag
- Group By in LINQ with a particular column
- Difference between Query Expression and Method Expression in LINQ?
- How do you return a default value if a LINQ to entities query returns no values
- Get string[] elements with index of int[] indices
- Why does Linq does not order my result immediately
- Merging two Arrays using LinQ
- Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique?
- Count Distinct - Inner Join - Group By / With the new Linq-to-NHibernate Provider
- Linq join two objects of the same type
- C# Linq query where Table A column is not equal/doesnt math Table B column join
- Generic Repository
- Remove parent items from a list when having chilid items by checking parent IDs of the list c#
- Create LINQ query at runtime to GroupBy in EntityFramework (with inheritance)
- Entity Framework Select Statement with Logic
- How would I use an anonymous result type for an expression delegate for LINQ to SQL?
- Grouping using linq to entity return non correct result
- how to return a property based on another property condition using LINQ in .NET Core
- Return an Object from Database.SqlQuery
- LINQ to SQL Take w/o Skip Causes Multiple SQL Statements
- How to filtering related entities but with no foreign keys
- LINQ without using cycle
- How to cast an `IEnumerable<Unknown T>` to `IEnumerable<Whatever>`
- How to get the GUID from stored procedure in sql to mvc
- GroupBy either of two properties in LINQ
- Retaining order with LINQ using .Contains
- How can I convert sql to linq
- LINQ to check if ID exists in List
- Get cell values from DataGrid
- Creating a dynamic Linq select clause from Expressions
- LINQ GroupBy Count