Generate entity class code from an Entity Data Model (EDM) prepared with the Entity Framework EDM Designer.
Alternatively, you could create your entity class model entirely in code using the "Code First" style and bypass the EDM design and generation process described here.
Add an Entity Framework Entity Data Model (EDM) to a project and examine the project in the Visual Studio "Solution Project" window.
The EDM Wizard and DevForce code generation have made significant changes to the project:
DevForce used the T4 code generator built into Visual Studio to create the source code file.
Source code files are regenerated automatically every time you save a change to the EDMX file.
You can also regenerate manually by selecting the .tt template file and choosing Run Custom Tool from the context menu.
The T4 code generator is directed by the DevForce code generation template which reads the EDMX and emits entity model source code file(s). The template file name shares the same root name as the EDMX file, SimpleNorthwind in this example.
The DevForce template only needs the CSDL section of the EDMX file because the .NET entity classes are entirely described by the conceptual entity model. That's why a DevForce entity class model can be designed in the Model First style which only has a CSDL.
There is only one generated source code file in this small example, SimpleNorthwind.IB.Designer.cs. There could be several generated source code files if the model were unusually large. You control the number of classes generated per file - and hence the number of files - by setting the "Max. Classes per File" model property in the EDM Designer.
The following snapshots of a generated class file shows three kinds of classes.
At the top is a model-specific EntityManager component. The EntityManager is the most important component in all of DevForce and you will get to know it well.
Below that are the generated entity classes, one after another, each one generated from the conceptual entity defined in your EDM.
DevForce generates true Entity Framework classes. You can perform pure Entity Framework operations with these class using EF's ObjectContext in textbook fashion. But the DevForce entity classes differ significantly in their support for distributed application scenarios, validation, property interception, and UI data binding.
The Customer class is typical:
Finally, at the bottom, is the EntityRelations class
C# | /// <summary> /// A generated class that returns the relations between entities in this model. /// </summary> public partial class EntityRelations : IbEm.IEntityRelations { ... |
VB | ''' <summary> ''' A generated class that returns the relations between entities in this model. ''' </summary> Partial Public Class EntityRelations Inherits IbEm.IEntityRelations ... |
Within the class are static EntityRelation fields defining every relationship between every entity in the model.
In general you customize the generated classes by adding more code to the model. You can trim back some of the emitted code by adjusting the generator control properties within the EDM Designer. You can replace all of the attributes with an entity metadata class.
If these paths prove insufficient, you can customize the code generation template yourself