当我尝试填充NotMapped字段时,我有一个错误(“无法在LINQ to Entities查询中构造实体或复杂类型'MyTable')。
这里有我的例子:我的代码中的错误是什么? 并且,是否可以在不填充字段的情况下填充ExternalDescription?
public partial class MyTable
{
public int MyTableId { get; set; }
public int Table2Id { get; set; }
public int Field1 { get; set; }
public int Field2 { get; set; }
[NotMapped]
public String ExternalDescription { get; set; }
}
public partial class MyTable2
{
public int MyTable2Id { get; set; }
public String Description { get; set; }
}
var records = (from t1 in db.MyTable
join t2 in db.MyTable2 on t1.Table2Id equals t2.MyTable2Id
select new MyTable
{
MyTableId = t1.MyTableId,
Table2Id = t1.Table2Id,
Field1 = t1.Field1,
Field2 = t1.Field2,
ExternalDescription = t2.Description
}).ToList();