当我执行代码时:
public List<T> GetCustomerTxList(int customerId)
{
var matchingPocos = new List<T>();
using (linq.AOMSEntities dataRepos = new linq.AOMSEntities())
{
IEnumerable txlist = from t in dataRepos.TransactionRecord
where t.CustomerReference.Value.Id == customerId
select t;
foreach (EntityObject entity in txlist)
{
matchingPocos.Add(entity.ConvertToPoco<T>());
}
}
return matchingPocos;
}
我得到以下异常: Data.Repository.Integration.Test.LinqRepositoryTest.GetCustomerTxList: System.NotSupportedException :在LINQ中不支持指定的类型成员'CustomerReference‘。仅支持初始值设定项、实体成员和实体导航属性。
CustomerReference是引用Customer实体的TransactionRecord实体上的EntityReference。
为什么不能使用实体引用进行查询?
执行此类查询的推荐方法是什么?
如果有帮助,我很乐意提供更多的信息/代码。
发布于 2010-02-25 21:22:56
您应该能够在查询中直接访问客户,如下所示:
from t in dataRepos.TransactionRecord
where t.Customer.Id == customerId
select t;
在这种情况下,EF将在幕后为您使用CustomerReference。
https://stackoverflow.com/questions/2337625
复制相似问题