I’m looking for a tool that will dynamically generate Linq to Entity queries from a given entity, a Query By Entity (Example), if you will. Given an entity and the object context it belongs to, the generator returns an ObectQuery or IQueryable that could be further modified or executed. Ideally, the query builder would not directly reference Entity Model, rather it would use the object context to build the query from the model. I imagine the code looking something like this:
QueryBuilder qb = new QueryBuilder(new EntitiesContext());
Customer c = new Customer();
qb.Add(c);
c.FirstName = "Jim";
var qry = qb.BuildQuery();
int total = qry.Count();
The underlying query would look something like this:
var query = from c in ctx.Customers
where c.FirstName == "Jim"
select c;
Does such a thing already exist somewhere? I can imagine coding something like this myself, but I would rather start using something that already exists.