0
我想通過將實體框架映射到列字段來構建一個動態謂詞:動態謂詞與實體框架
在where子句我已經進入??因爲我不知道要放什麼東西在那裏,我想這是動態的,就像在這篇文章中,雖然這並不在EF工作我的; Y的LINQ to SQL:
How to specify dynamic field names in a Linq where clause?
例如:
我有一個枚舉:
public enum SearchTypes {
FirstName = CustFName,
LastName = CustLName
}
我的方法是這樣:
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();
}
有沒有人有建立基於枚舉的表達式的方式?
檢查[我對這個問題的回答](http://stackoverflow.com/questions/3752305/declaring-funcin-t-out-result-dynamically/3753377#3753377)看看如何建立一個動態linq查詢與'Expression'。 – 2010-10-14 03:02:11