代码之家  ›  专栏  ›  技术社区  ›  Paul

查询entityreference时出现问题

  •  2
  • Paul  · 技术社区  · 15 年前

    当我执行代码时:

            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(数据存储库集成测试linqrepositorytest.getcustomertxlist): System.NotsupportedException:指定的类型成员“customerreference”在linq to entities中不受支持。仅支持初始值设定项、实体成员和实体导航属性。

    customerreference是引用客户实体的transactionrecord实体的entityreference。

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

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

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

    1 回复  |  直到 15 年前
        1
  •  5
  •   bendewey    15 年前

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

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

    在这种情况下,ef将为您使用customerreference。