Entity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime
-
I'm using entity framework I'm trying to make a general function that works for an object for which the class is known only at runtime. I have an instruction that use an expression similar to this :
context.ChangeTracker.Entries(of Myobj1)
Of course that if I know the class name "MyObj1" the above expression is working correctly. But at runtime , I only have an variable :
Dim tp as type
which contain the class , and i need an expression like this :
context.ChangeTracker.Entries(of tp)
Thank you !
-
I'm using entity framework I'm trying to make a general function that works for an object for which the class is known only at runtime. I have an instruction that use an expression similar to this :
context.ChangeTracker.Entries(of Myobj1)
Of course that if I know the class name "MyObj1" the above expression is working correctly. But at runtime , I only have an variable :
Dim tp as type
which contain the class , and i need an expression like this :
context.ChangeTracker.Entries(of tp)
Thank you !
My bad. I misunderstood what you were doing. In order for a Generic to work, the types used must be known at compile-time, not run-time. I've never done what you're trying to do, nor seen it done specifically with EF before, but you may want to look into these[^] possibilities. You'd have to create a method that generates the entire ChangeTracker.Entities() call at runtime.
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak