IMHO this is too complicated. Why do you have a POCO object for saving and a separate object for working with data loaded into a POCO object? It looks like your application is still archived.
ORM stands for relational object mapping. This means comparing the world of relations and the object world. Usually this can also be translated as a mapping between a database and business objects. Therefore, you should use POCO objects as your business objects. This is the meaning of using POCOs. If you do not want to use them as business objects, you do not need them, and you can directly use the default object objects.
If you want to use POCOs as a business object, just let the EF generate these POCOs for you and add a partial class to each POCO that defines your methods.
Btw. your business object actually looks like an implementation of an Active Record pattern . If you want to use these templates, perhaps you should check out the Windsor Active Record , which is based on the top of NHibernate.
Edit:
Well. You can use your classes instead of the generated POCO objects.
One way is to abandon EFv4 and EDMX and check out the new EFv4.1 and its new free API (also code-based) for display. This is the whole for a separate question or just use the search here on SO.
You can do this with EDMX. There are some basic rules that you must follow in order to do this work, because all this is done using naming conventions. Since you already have classes, you must modify this in the EDMX file so that the conceptual model is the same as your business objects:
- Each business object that must be saved or loaded must have an object in the conceptual model.
- The entity must have the same name as the business object. You must also properly configure the object in the properties window (abstract, access level and base object must be the same as in your business object).
- Each stored property in a business object must have a property in the object in the conceptual model. Again, you must properly configure each property (accessibility getter and setter, type, nullable, etc.).
EDMX consists of three layers:
- SSDL - a description of the database. It is almost always created, and you cannot change it directly in the designer.
- CSDL - A description of the objects that should be the same as your business objects. This is what you change in the designer. You can rename the fields as you wish.
- MSL - mapping between SSDL and CSDL. If you open the context menu for any object in the designer, you will see a table display. It will open a window with the definition of the mapping between CSDL and SSDL.
These are basic rules, but since you already have business objects, you will most likely find situations where it will be difficult to match them. The best way is to simply ask for this particular problem. This will most likely be due to some complex properties, navigation properties, or inheritance.
source share