مشكلة في الاستعلام مع الكيان
-
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 هو كيان على كيان TransactionRecord يشير إلى كيان العميل.
لماذا لا يمكنني الاستعلام باستخدام مرجع كيان؟
ما هو النهج الموصى به لأداء مثل هذا الاستعلام؟
سأقدم بكل سرور المزيد من المعلومات/التعليمات البرمجية إذا كان يساعد.
المحلول
يجب أن تكون قادرًا على الوصول إلى العميل مباشرة في استفسارك مثل هذا:
from t in dataRepos.TransactionRecord
where t.Customer.Id == customerId
select t;
تحت الأغطية ، ستستخدم EF جهاز العميل لك في هذه الحالة.
لا تنتمي إلى StackOverflow