実体参照で問い合わせる問題
-
22-09-2019 - |
質問
私は、コードを実行すると:
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は、Customerエンティティを参照するTransactionRecordエンティティ上のEntityReferenceです。
私は、クエリエンティティ参照を使用することができないのはなぜ?
は、このようなクエリを実行するために推奨されるアプローチは何ですか?
それが助け場合、私は喜んでより多くの情報/コードを提供します。
解決
あなたはこのようなクエリで直接お客様にアクセスできるようにする必要があります:
from t in dataRepos.TransactionRecord
where t.Customer.Id == customerId
select t;
EFは、このような場合にはあなたのためCustomerReferenceを使用するカバーの下ます。
所属していません StackOverflow