I really have two questions:
- What is the difference between an Entity Framework Entity object and an ADO.NET C# POCO Entity.
- Do I have updating a record using a repository correct below?
If you turn off code generation, then add the ADO.NET C# POCO Entity Generator, it provides a nice class representation of your Entity Framework 4 objects. The idea is that (from here):
The POCO Template can be used to generate persistence ignorant entity types
from an Entity Data Model.
However, these objects have the relations between objects as well as a link back to the database. For example, you can pull one out of your repository, alter it, then save changes at the repository or unit of work level, and it saves the content to the database.
So my question is what is different between a native Entity Framework object and these POCOs generated using this tool?
This is what I think when I update a record using a repository. Is this wrong?
- Request a POCO from the repository.
- The Repository loads the records from the data context, creates a new POCO for each record found, copies the values from the Entity Framework objects to the POCOs, and returns a collection of the new POCOs.
- Changes are made to these POCOs outside of the repository, then the POCOs are submitted back to the repository using something like Save(POCO).
- The repository loads the matching records from the database and copies the POCO properties to the Entity Framework objects.
- One calls Save using either the repository object or unit of work object.