【发布时间】:2010-10-24 01:01:53
【问题描述】:
如果我有如下课程:
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 和 Name 值,其余为空。
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.
你会怎么做呢?我需要指定所有类的字段吗?
【问题讨论】:
-
您找到解决问题的好方法了吗?
标签: c# linq-to-entities entity-framework-4 projection