Last post Sep 15, 2014 03:26 PM by ossprologix
Sep 11, 2014 12:30 PM|ossprologix|LINK
Let's say I have a UI with lots with predicates stuffs such as age [less than/greater than/equal to] and name [startsWith/Contains/Equals] things like that which helps in searching.
We been doing it using dynamic query generation. It hasn't been much we've started using EF.
I can see lamda where i cud put in predicate like Func returning bool in Persons.Where().
What are the best practices?
Person [Name, Age, Title]
User searches for person with different variations based on properties on Person entity.
How to do dynamic EF lamda functions such as Where()?
something to do with expression tree?
Sep 11, 2014 08:10 PM|jsiahaan|LINK
Here a sample that may help:
var dataSource = (
from c in source
where(c.Name.ToLower().Contains(aString.ToLower()) && c.LongDescription.ToLower().Contains(aString.ToLower())
select new HierarchyDataService()
Id = c.Id,
ParentId = c.ParentCategoryId,
Name = c.Name,
Level = c.CategoryLevel
If you need exact letter or case sensitive, you may remove ToLower(). The example is case insensitive.
Sep 15, 2014 03:26 PM|ossprologix|LINK
i think expression trees and dynamic expression tree are what i will go for