3

I have multiple existing SQL Server databases for different clients that have schemas that are 95% similar, but may have a few extra custom columns in each database to handle some specific customer need.

For example, database A might have a table with two custom columns:

StdColumn1, StdColumn2, CompanyACustom1, CompanyACustom2

and database B might have one custom column:

StdColumn1, StdColumn2, AnotherCompanyCustom1

and database C might have no custom columns, just:

StdColumn1, StdColumn2

I would like to configure Entity Framework so that the C# objects have some extra predefined properties (eg: CustomColumn1, CustomCustom2, etc.) that map to these custom columns if they exist, or have no effect if a custom column doesn't exist.

Views would be one way to do this, but I was wondering if I could use the CSDL, SSDL, and MSDL files to do something like this. Or perhaps this technology could be made to work?

1 Answer 1

1

Entity Framework is a compile-time framework that must know the schema ahead of time. It doesn't have a dynamic mode, which is what you need. But there are a few Entity Framework "extensions" out there that use EF underneath the covers and compiles the model at runtime instead. The downside is that you would be required to use 'dynamic' objects to interact with it (since type isn't known at compile time).

Premade extensions... Entity Framework Dynamic Data Model Builder Entity Framework Runtime Model Adapter

Or you can roll your own solution whereby you adjust your SSDL and MSL files using XML manipulation... http://social.msdn.microsoft.com/Forums/en-US/6ed96028-0d43-4ab7-ade6-d5aaf3ffd6cf/updating-the-entity-framework-at-runtime

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.