简体   繁体   中英

Find the Name of Objects referenced in IQueryable and IEnumerable in ENtity Framework

I am creating a generic function that have the function definition as:

  public static List<T> Func_IEnumerable<T>(this IEnumerable<T> q, ObjectContext dc, string CacheId)

and one function as

  public static List<T> Func_IQueryable<T>(this IQueryable<T> q, ObjectContext dc, string CacheId)

The question is that I want to find out the tables name,procedure name,function name and/or view name referenced in the Ienumerable or IQueryable Query

Is it possible with the Linq framework

And if not then we may convert the IEnumerable into System.Data.Objects.ObjectQuery and finally using ToTraceString to get the pure SQL.

Now from Pure Sql can we get the object names.

Whether Sql Server has some functions to do the same if not, then how should I parse it to get desired results.

Thanks,

Any help is appreciated.

If you want to use SqlCacheDependency (featrue heavily dependent on SQL) why are you using EF (feature which tries to hide SQL as much as possible) in the first place? You are combining two features which were not designed to work together - that happens quite often in .NET framework.

IQueryable can be converted to ObjectQuery only if the object is ObjectQuery = it was created as query on exposed ObejctSet and you have never called ToList , AsEnumerable or other executing method on it. This also means that calling to stored procedure cannot be converted to ObjectQuery .

Real IEnumerable (executed query) cannot be converted to ObjectQuery and you cannot get any information about source of the result set from IEnumerable . This is case for all queries where ToList or AsEnumerable was called and for example for all calls to mapped stored procedures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM