|
|
Released: Entity Framework Runtime Model Adapterby Brandon HaynesSunday, September 13, 2009 at 05:39 PM EDTThe ObjectContext is a base class for all Entity Framework models. While there exists a rich API for interacting with a model, the ability to adapt the underlying schema to the (potentially varying) run-time environment presents a serious shortcoming for many production applications. These variances can potentially involve myriad considerations, from a change in database owner to modified table names (often by a production-specific prefix). This can have a serious impact on large-scale deployment of applications using the Entity Framework (those familiar with my DotNetNuke-related work will immediately understand this consideration, where a run-time environment may be configured to use an arbitrary database owner or table prefix). To remedy this issue, I have developed an adaptive framework that converts an Entity Framework model generated by the Visual Studio designer into a highly configurable result. This framework is designed to be flexible, extendable, and highly customizable.
My goals for any satisfactory solution were as follows:
It is unfortunate that the object model exposed by the Entity Framework is so frustratingly difficult to extend. The underlying metadata are overwhelmingly read-only (and, frustratingly, many potentially useful classes are either internal or sealed). Indeed, it seemed that there was no simple remedy to the problem at hand. My solution utilizes the following approach:
I use dependency injection to adapt attributed entities (database, table, and function names) into their adapted counterparts. Additional adapters could easily be constructed for other domains, should any arise (to illustrate this point, a NonTransformingAdapter is included in the release, which performs no transformations). Click here to access the project site for additional details and downloads. As is all of my DotNetNuke-related work, this framework is available under a liberal open-source license for ready public consumption (and extension). Though the content herein is protected under the license below, be sure to consult the project license (New BSD) for integration-related details. As always, feedback is appreciated. B This article originally appeared on From the Desk of Brandon Haynes. |
|