Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to an Entity Model using Reflection

Tags:

I'm writing a little utility to load Entity Data Models from an assembly and query against them.

I've tried using Reflection to load a derived ObjectContext, but ObjectContext doesn't derive from MarshalByRefObject so I can't pass parameters to the constructor with Activator.CreateInstance() (according to the exception I get.)

Is it possible to load an Entity Model defined and stored in an external assembly using Reflection, "late bind" to the EDM, and perform queries against it if you provide a valid connection string?

like image 426
Dave Swersky Avatar asked Feb 27 '10 17:02

Dave Swersky


1 Answers

I believe ObjectContext.Metadataworkspace.LoadFromAssembly() is what your looking for:

http://msdn.microsoft.com/en-us/library/bb495513.aspx

like image 156
John Farrell Avatar answered Nov 15 '22 09:11

John Farrell