如果我有類似下面的類:實體框架4:如何將投影編碼到類類型?
public class Customer {
public int id {get;set;}
public string name {get;set;}
public string line1 {get;set;}
public string line2 {get;set;}
public string line3 {get;set;}
public string line4 {get;set;}
}
,我只想要選擇的ID和名稱值,保留其餘空。
var myCustomerList = DC.Customer.Select(
p => new Customer { id = p.id, name = p.name });
我得到以下錯誤:
The entity or complex type 'MyModel.Customer' cannot
be constructed in a LINQ to Entities query.
你會做怎麼回事呢?我是否需要指定所有類的字段?
您是否找到解決問題的好方法? – Learner 2014-02-11 15:02:45