0

In the official documentation, it's mentioned that DTOs can be used as breeze entities:

It does not have to be an ORM class. It could be a DTO class that you will later map into a class in your business model via your implementation of BeforeSaveEntities.

In a comment by Ward Bell, he suggests the following strategy for saving DTOs alongside EF Entities:

  1. Remove DTO from EntityInfos
  2. Retrieve corresponding business model entity from Db (or create such an entity if this is an insert)
  3. Update this copy from DTO
  4. Add this entity to the EntityInfos (don't forget the OriginalValues properties for an update)
  5. Rinse and repeat for all such DTOs
  6. Let it go ... and EF will save it
  7. Intercept the "after save" and remap the updated/inserted business entity into its DTO form in the SaveResult so that you send the DTO, not the "real" entity, back to the client.

The problem with this recommendation is with step 4. The EntityInfo.Entity property is defined as internal. How can you create an EntityInfo with the proper EF Entity?

One alternative to this recommendation would be to override the SaveChangeCore method and handle the mapping of DTOs to EF Entities in that method. The downside to this is that the EFContextProvider.SaveChangesCore has a lot of code and I'd rather not duplicate that effort.

1 Answer 1

0

I found ContextProvider.CreateEntityInfo(). It has an overload that accepts an entity and sets the EntityInfo.Entity property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.