I'm trying to come up with a solution that allows a user to pass an entity into a method and have that method build a LINQ query dynamically.
List<object> items = new List<object>();
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
LinqMetaData metaData = new LinqMetaData(adapter);
var q = (from cm in metaData.ContractMaster
select cm)
.WithPath(p => p.Prefetch(cm => cm.ContractDetail));
if (contract != null)
{
IEntityField2[] fields = new IEntityField2[contract.Fields.Count];
contract.Fields.CopyTo(fields, 0);
var populatedFields = from f in fields.AsQueryable()
where f.IsChanged
select f;
foreach (IEntityField2 f in populatedFields)
{
q = q.Where(all => all.Fields[f.Name].CurrentValue.Equals(f.CurrentValue));
}
}
foreach (object o in q)
{
items.Add(o);
}
}
My code is failing on the addition of my Where clause:
The property 'Fields' isn't mapped to a field or database construct of entity type 'ContractMasterEntity'. Did you mean to call an extension method instead? ('Count' vs. 'Count()') ?
Does anyone know how to accomplish what I'm trying to do?
Many thanks!