当我执行的代码:

        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:指定的类型成员“CustomerReference”不是在LINQ支撑到实体。只有初始化器,实体成员和实体导航属性都支持。

CustomerReference是在TransactionRecord实体引用一个顾客实体的EntityReference。

为何无法查询中使用的实体引用?

什么是执行这样的查询建议的方法?

我会很乐意提供更多的信息/代码是否有帮助。

有帮助吗?

解决方案

您应该能够直接访问客户在您的查询是这样的:

from t in dataRepos.TransactionRecord 
where t.Customer.Id == customerId 
select t;

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top