DotNetNuke Entity Framework Model Adapter
More details about this project may be found on my blog
An ObjectContext adapter allowing DotNetNuke modules using the Entity Framework to automatically apply a runtime database owner and object qualifier.
This project enables a commercial DotNetNuke module development path for those who wish to leverage the Entity Framework.
- Run-time adjustment of an Entity Framework EDMX model to conform to any given DotNetNuke installation, including:
- Connection-based adaptation (e.g. use of a runtime-specified connection string)
- Run-time adjustment of model schema to effectuate:
- Adjusting data-level table and stored procedure prefixes to match the DotNetNuke installation ObjectQualifier
- Adjusting the owner of database objects to match the DotNetNuke installation DatabaseOwner
- Continued use of the Visual Studio Model designer
- No tedious changes in the compiler-generated code
- Continued use of an assembly-embedded EDMX model (and thereby no additional or external schema deployment files)
The Entity Framework ObjectContext
allows development using the workspace model automatically generated by the Visual Studio designer. However, when deployed within DotNetNuke
, this model would need to be adjusted at runtime for whatever contextual object qualifier and database owner were in use by an end-user. Unfortunately, the API exposed by the Entity Framework system is overwhelmingly read-only (and, frustratingly, many classes are internal and sealed) and there was no simple remedy to this problem. Until now.
This solution extends the Entity Framework runtime model adapter
to operate within a DotNetNuke extension, allowing a developer to design against an unqualified, dbo-owned DotNetNuke instance and be assured that it will deploy (and operate) correctly on any configuration that an end user might have deployed. Adaptation is largely inexpensive, and since the models are cached by type, performance is not significantly affected.
- Download the latest release
- Add a reference to the DotNetNuke model adapter assembly (BrandonHaynes.ModelAdapter.EntityFramework.DotNetNuke)
- This will include an indirect reference to the general Entity Framework Model Adapter framework (BrandonHaynes.ModelAdapter.EntityFramework)
- Add or edit your EDMX designer file in Visual Studio (or using any external tool) as normal
- Change the base class of the resulting ObjectContext to BrandonHaynes.ModelAdapter.EntityFramework.DotNetNukeModelAdapter
- Note that the Visual Studio EDMX editor UI does not expose the ObjectContext base class as an editable field. As such, it must be edited manually in the underlying generated code.
- Additionally, this base class must be updated with each modification to the model (as the code is, perhaps obviously, regenerated).
- This is especially unfortunate, and it is hoped that a future version of the editor would expose method by which this base class might be modified via the UI.
- Ensure that the DotNetNuke adapter assembly (BrandonHaynes.ModelAdapter.EntityFramework.DotNetNuke.dll) and Entity Framework adapter assembly (BrandonHaynes.ModelAdapter.EntityFramework.dll) are deployed with the project
Example Base Class Adjustment
By way of example, a designer-generated ObjectContext might read as follows before adjustment:
public partial class MyEntities :
This base class should be changed to read:
public partial class MyEntities :
No other modifications are necessary.
Module developers must develop against a DotNetNuke installation with no
object qualifier. This adapter does not store the design-time object qualifier for later removal. Any design-time database owner may be used; the design-time value is replaced regardless of original configuration.
This project utilizes the generalized Entity Framework Model Adapter
, which allows for arbitrary adjustment of an Entity Framework EDMX at runtime. More details about this project may be found on its homepage
Feedback about your experiences is needed, and greatly