This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I have a seemingly a simple question but I do not know the answer. Given a table name (it has to be string type), I need to find IQueryable and run a linq query. The following does not work because IQueryable doesn't know the entity type. IQueryable iqueryable = uow.GetType().GetProperty("tablename").GetValue(uow, null) as IQueryable; iqueryable.Where(e => e.Id == 1); // <- this won't work.
Does anyone know how to do this? I appreciate for your help. -chris
|
|
|
You may be able to do it with a "dynamic LINQ" library (Google around, there are a few out there), but probably the easiest solution is to recognise that you have left the world of strong types, and drop back to the weak-typed query objects API: Assembly asm = typeof(SomeArbitraryEntity).Assembly; // or GetExecutingAssembly() or whatever If you need more flexibility than FindById, you can write e.g. Find(type, Entity.Attribute("Id") == 1); but for Id lookups you should use FindById because it can avoid the database query if the entity is already in the UOW. See http://www.mindscapehq.com/documentation/lightspeed/Basic-Operations/Querying-the-Database-Using-Query-Objects for more info. |
|
|
Oh... I see. Thanks for the pointer. Cheers! -chris
|
|