In the previous post, we have seen how we designed our application with CodeFluent Entities. We will now take a look to how we did with Entity Framework 5 to conclude on a comparison of those two designers.
Using Entity Framework 5
Entity Framework is a tool that allows developers to create applications that access to data from a conceptual model. In order to create our model, we will need to add new “.edmx” file to our project as it is showed on the following screenshot.
Once this file added, we can see the Entity Framework model. From this model we are able to create:
- Entities,
- Properties
- And relations.
As you can see in the screenshot below, the Entity Framework designer is composed by a designing surface and a right click contextual menu.
Following the same path than our first article, we will start by adding a new entity to our model. To do so we will perform a right click on the surface then hit ‘Add New > Entity…’. According to our project we will name it ‘Category’. We will set the value of entity set to ‘Category’ and we will name our key property ‘Id’ of type ‘Int32’.
In order to demonstrate other features, we will add two other properties: Description and Name of type string. We will also create a new entity named ‘Product’ with an entity set named ‘Product’ and a key property name set to ‘Id’ of type ‘Int32’. This entity will contain three other properties: Name, Description and Image, respectively of types: string, string, and binary.
Unlike CodeFluent Entities Entity, Framework does not provide types like ‘Image’ or ‘email’. Right now, it’s not really important but we will get back to it in an upcoming article dedicated to the generation and you will see that it saves you tons of work regarding BLOBs storage.
We will now add a one-to-many relation between these two entities. To do so, right click on the ‘Category’ entity, hit ‘Add New > Association’ and a popup will show up. In this popup, modify the fields according to the following screenshot to create our relation properly.
As you can see on the screenshot above, Entity Framework created navigation properties and a foreign key property named ‘CategoryId’ for us.
This is pretty much all we can do for this project with Entity Framework 5 since we don’t need: complex properties, inheritance, or function import functionalities.
Finally, regarding the validation of our properties (e.g. required attributes), we will have to do it in partial classes once we will have generated our model classes thanks to T4 Templates.
Note: we could have choose to customize T4 templates in order add those required attributes directly in the generation process but we wanted to keep things as close as possible to what is provided out-of-the-box.
Comparison and conclusion
On these two articles, we talked about CodeFluent Entities and Entity Framework designers’ capabilities and we are now able to do some comparison between them.
Starting with the property types we have seen that CodeFluent Entities offers a lot more types for properties. CodeFluent Entities advanced types as ‘image’ allows developers to gain a lot of time because as you will see in the upcoming post treating about generation CodeFluent Entities will generate columns to store information about the image and it will also generate for you a BLOB handler.
Regarding relations between our entities CodeFluent Entities allows you to set cascade for save and delete directly when you create the relation.
One of the most important problem with Entity Framework is the generation process. Unlike CodeFluent Entities, which have a continuous generation process that allows you to update your model at any time and generate over the current one, using Entity Framework, if you want to update and regenerate your model, you will have to drop the existing database, recreate a new one and regenerate model classes by adding new code generation item.
Another key point is the impossibility to add attributes, rules or custom methods directly from the model with Entity Framework. While CodeFluent Entities provides these features out-of-the-box, with Entity Framework you will have to either customize your T4 template, create partial classes to extend the code generated or write T-SQL to create your stored procedure.
Finally, CodeFluent Entities allows you to create instances directly from the model, therefore it gives the possibility to have data in your database directly after the generation.
Note: You can find more detailed information about the differences between the CodeFluent Entities and the Entity Framework designers reading this white paper (http://www.softfluent.com/docs/codefluent/codefluent-entities-entity-framework.pdf)
In conclusion, we can see that CodeFluent Entities modeler is more powerful and flexible than Entity Framework designer while providing continuous generation and more features.
Cheers,
The SoftFluent Team.
