使用 EntityReference 查询时出现问题
当我执行代码时:
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 to Entities 不支持指定的类型成员“CustomerReference”。仅支持初始值设定项、实体成员和实体导航属性。
CustomerReference 是引用 Customer 实体的 TransactionRecord 实体上的 EntityReference。
为什么我无法使用实体引用进行查询?
执行此类查询的推荐方法是什么?
如果有帮助,我很乐意提供更多信息/代码。
When I execute the code:
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;
}
I get the following exception:
Data.Repository.Integration.Test.LinqRepositoryTest.GetCustomerTxList:
System.NotSupportedException : The specified type member 'CustomerReference' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
CustomerReference is an EntityReference on the TransactionRecord entity referencing a Customer entity.
Why can I not query using an entity reference?
What is the recommended approach to perform such a query?
I'll gladly provide more info/code if it helps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够在查询中直接访问 Customer,如下所示:
在这种情况下,EF 将在幕后为您使用 CustomerReference。
You should be able to access the Customer directly in your query like this:
Under the covers EF will use the CustomerReference for you in this case.