Hello,
I'm facing an issue that I'm hoping to get your input on. I use LINQ to chain multiple where clauses, which is working great. However, some tables in my DB are dynamically generated and I only know their name at run-time. However, they all have similar structure, so I'd like to construct a query that joins to those tables (they do not have entities generated, but I can safely project to a dummy entity). Basically, I'm looking for something like this:
using (var a = DataAccessAdapter)
{
var x = new LinqMetaData(a);
//This starts the base query
IQueryable<EventEntity> q = from e in x.Event select e;
//Add some where clauses based on generated entity attributes
q = q.Where(z => z.Attribute1 == "abc"); //this is working great
q = q.Where(z => z.Attribute2 == 123); //this is working great
//Here I'd to join to a dynamic table to inject a custom WHERE clause. Is something like this possible? Table XYZ does not have a generated entity, but if I can project it to a dummy entity CustomTableEntity that has only one column ObjectId and join with the rest of the query, that would really help.
q = q.Where(z => x.AdapterToUse.FetchQuery<CustomTableEntity>("select ObjectId from XYZ where col1=99").Where(c => c.ObjectId == z.Id).Any());
var results = q.ToList();
}
Thanks in advance!
Albert