2

コードを実行すると:

        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'はLINQtoEntitiesでサポートされていません。初期化子、エンティティメンバー、およびエンティティナビゲーションプロパティのみがサポートされます。

CustomerReferenceは、Customerエンティティを参照するTransactionRecordエンティティのEntityReferenceです。

エンティティ参照を使用してクエリできないのはなぜですか?

そのようなクエリを実行するために推奨されるアプローチは何ですか?

それが役に立ったら、私は喜んでより多くの情報/コードを提供します。

4

1 に答える 1

5

次のように、クエリで顧客に直接アクセスできるはずです。

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

この場合、EFはお客様に代わってCustomerReferenceを使用します。

于 2010-02-25T21:22:56.290 に答える