Problema interrogazione con EntityReference
-
22-09-2019 - |
Domanda
Quando eseguo il codice:
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;
}
ottengo la seguente eccezione: Data.Repository.Integration.Test.LinqRepositoryTest.GetCustomerTxList: System.NotSupportedException: L'elemento tipo specificato 'CustomerReference' non è supportato in LINQ alle entità. Sono supportati solo inizializzatori, i membri di entità, e le proprietà di navigazione entità.
CustomerReference è un EntityReference sull'entità TransactionRecord riferimento a un'entità Customer.
Perché non è possibile interrogare utilizzando un riferimento di entità?
Qual è l'approccio consigliato per eseguire una query?
Sarò lieto di fornire maggiori informazioni / codice se aiuta.
Soluzione
Si dovrebbe essere in grado di accedere al cliente direttamente nella vostra domanda in questo modo:
from t in dataRepos.TransactionRecord
where t.Customer.Id == customerId
select t;
Sotto le coperte EF useranno il CustomerReference per voi in questo caso.