NHibernate, DTOs to Entities vs keys and relations
Posted: Thu 27 Mar 2014 16:18
Hi,
Using Entity Developer for NHibernate (running v 5.5.164) I am trying figure out how to do the following correctly:
An model of entities server side, plus DTOs generated for each entity going via WCF to client side.
Now server side entities I would prefer having full navigation properties, while client side I would prefer having foreign keys available in DTOs - or optimally fine tune which relations that the generated converters should map into nested objects/navagation properties, and which should just result in visible/editable foreign keys in the DTOs.
1) But I am fighting with limitations in both NHibernate and Entity Developer, which does not allow fine tuning as above!?
2) To get keys in DTOs it seams like model settings need the "Include foreign key columns" whereby they are also visible in the Entities, but that confuses NHibernate (two things referring to the same database field) - at least I have not yet been able to get it to save a entity.
3) The generated converters cannot handle DTO to Entity for navigation properties/relations. What should be the strategy for reestablishing these in a way that works consistently so that NHibernate's lock()/update()/save()/merge() works?
(As I started with writing, there is the problem of keys versus navigation properties in the two different objects, so while I don't mind writing custom glue code for checking and reestablishing integrity of relations, I do need the right data available for doing it.)
Note: Previously I have bypassed this problem by generating all entities without any navigation properties at all, and with all foreign keys visible as plain fields, so the model basically becomes DTOs in itself. That I have gotten to work well. But for my next project I wanted to use the power of generated DTOs client side plus full model server side.
Bests
Allan K.
Using Entity Developer for NHibernate (running v 5.5.164) I am trying figure out how to do the following correctly:
An model of entities server side, plus DTOs generated for each entity going via WCF to client side.
Now server side entities I would prefer having full navigation properties, while client side I would prefer having foreign keys available in DTOs - or optimally fine tune which relations that the generated converters should map into nested objects/navagation properties, and which should just result in visible/editable foreign keys in the DTOs.
1) But I am fighting with limitations in both NHibernate and Entity Developer, which does not allow fine tuning as above!?
2) To get keys in DTOs it seams like model settings need the "Include foreign key columns" whereby they are also visible in the Entities, but that confuses NHibernate (two things referring to the same database field) - at least I have not yet been able to get it to save a entity.
3) The generated converters cannot handle DTO to Entity for navigation properties/relations. What should be the strategy for reestablishing these in a way that works consistently so that NHibernate's lock()/update()/save()/merge() works?
(As I started with writing, there is the problem of keys versus navigation properties in the two different objects, so while I don't mind writing custom glue code for checking and reestablishing integrity of relations, I do need the right data available for doing it.)
Note: Previously I have bypassed this problem by generating all entities without any navigation properties at all, and with all foreign keys visible as plain fields, so the model basically becomes DTOs in itself. That I have gotten to work well. But for my next project I wanted to use the power of generated DTOs client side plus full model server side.
Bests
Allan K.