Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Error using Contains

$
0
0

I have two entities in the model, Audit and Audit_Measure. They are in a many to many relationship which is reflected in the model.
i.e. Audit has a virtual ICollection Audit_Measures, and Audit_Measure has a corresponding virtual ICollectionAudits.

I am trying to return a list of Audit_Measures, for a particular Audit.

Assuming the usual try..catch..using etc, the code is:

audit_measures_in_audit = await db.Audit_Measures
                        .Where(am => am.Audits.Contains(audit))
                        .ToListAsync();

It's falling over on the 'Contains' clause with an exception:
"Unable to create a constant value of type 'CACS_GNS_Data.Models.Audit'. Only primitive types or enumeration types are supported in this context.."

I have since managed to get around it, but am not sure why I am getting the error.
Surely this is why the virtual collections exist in the model.

Thanks


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>