Hi, I am trying to build a dynamic predicate with Entity Framework by mapping an enum to the column field:
In the where clause i have entered ?? as i am not sure what to put there, i want this be dynamic like in this article, although that doesn't work me in EF on;y linq to sql:
http://stackoverflow.com/questions/2497303/how-to-specify-dynamic-field-names-in-a-linq-where-clause
For example:
I have an enum:
public enum SearchTypes {
FirstName = CustFName,
LastName = CustLName
}
My method is as such:
private static IEnumerable<CustomerSearchInfo> GetCustomers(String customerName, SearchType searchType)
{
using (var context = new NewgenEntities())
{
return context.tblCustomers.Where(??).
Select(p => new CustomerSearchInfo
{
FirstName = p.CustFName,
LastName = p.CustLName,
Id = p.CustID,
EmailAddress = p.CustEmail,
Mobile = p.CustMNumber,
Phone = p.CustPNumber
}).ToList();
}
Has anyone got a way of building an expression based on a enum?