首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用EntityReference查询时出现问题

使用EntityReference查询时出现问题
EN

Stack Overflow用户
提问于 2010-02-26 05:07:09
回答 1查看 916关注 0票数 2

当我执行代码时:

代码语言:javascript
运行
复制
        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。

为什么不能使用实体引用进行查询?

执行此类查询的推荐方法是什么?

如果有帮助,我很乐意提供更多的信息/代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-26 05:22:56

您应该能够在查询中直接访问客户,如下所示:

代码语言:javascript
运行
复制
from t in dataRepos.TransactionRecord 
where t.Customer.Id == customerId 
select t;

在这种情况下,EF将在幕后为您使用CustomerReference。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2337625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档