Connect to an object model using Reflection

I am writing a small utility to load Entity data models from an assembly and query them.

I tried using Reflection to load the derivative ObjectContext, but it ObjectContextdoesn’t follow from MarshalByRefObject, so I cannot pass parameters to the constructor using Activator.CreateInstance()(according to the exception I get.)

Is it possible to load the Entity model, defined and stored in an external assembly, using Reflection, "late binding" to EDM and execute queries against it if you specified a valid connection string?

+5
source share
2 answers

, ObjectContext.Metadataworkspace.LoadFromAssembly() - , :

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

+5

EDM, ObjectContext, ConnectionString, . .

    public const string ConnectionString = "name=My_Entities";
    public const string ContainerName = "My_Entities";

    #region Constructors

    public My_Entities()
        : base(ConnectionString, ContainerName)
    {
        Initialize();
    }

    #endregion

ObjectContext.Connection.

0

All Articles