Last post Jan 18, 2017 09:31 AM by Cathy Zou
Jan 01, 2017 01:14 PM|Anirban Ghosh|LINK
With a surprise I have found this. See the attached screen shots. I have a DbContext object "db" and I tried both the options and the result is surprising to me.
DbContext.Set() and dbContext<TEntity).Set are returning different objects.
The problem is: I am getting the Type of Object to be created at runtime and running the Dynamic Linq on that. So I am using DbContext.Set(Type) method to create the Object.
But in that case Expression of the queryable Object is getting changed and can not be able to Query the Object.
Note: If the above inserted image is shown broken, please right click and Open Image in a new tab.
Jan 03, 2017 06:56 AM|Cathy Zou|LINK
Hi Anirban Ghosh,
From the picture you provide. the return value of DbContext.Set(thisType) and DbContext.Set<Employee>() is same. the different you find may be the namespace. However, the result of the two method are some.
if you replace thisType with Employee. I think that you will find the result are the same not only in the return value but also in the namespace.
Through the following link about DbContext.Set<TEntity> Method and DbContext.Set Method (Type). you will find the two method's return value is
A set for the given entity type.
Jan 05, 2017 06:25 PM|Anirban Ghosh|LINK
Thanks for your reply. the problem is we have a defined function as follows:
public static IQueryable<T> ReturnPath<T>(this IQueryable<T> pathQuery)
// Some other code
return QueryablePath(pathQuery, Some other parameter);
db.Set(Type type).AsQueryable() can not access this function but db.Set<T>().AsQueryable() can, but I come to know about the class object to be queried of only at runtime, so can not use db.Set<T>()
Is there any work around?
Jan 18, 2017 09:31 AM|Cathy Zou|LINK
I try my best to find any solution. However, as far as I know, I got nothing.