This question is locked. New answers and comments are not allowed.
I have a general question related to how is best to handle interaction between business objects and ORM objects.
The two approaches I have used so far are as follows:
1. Store ORM Object - In this approach I get the "customer" orm object using linq and then store it as a private/protected variable in the business object. My business object properties simply get or set the underlying orm objects properties.
The big problem I have found with this approach is that once I have retrieved an orm object I also need to persist the context as you cannot fetch from one context and update in another. I either need to store the context with the object in my class ro store it globally - neither of which I like.
2. Populate Business Object - My second approach was to retrieve the customer orm object then map the properties of this object to the properties of my business object. So far so good. The problem I have found with this approach is that when saving changes, instead of updating the record based on its ID, it always inserts a record when I create a new orm object. The only way around this appears to be to query the database for the orm object first, then update it and save the changes. I don't particularly like this approach either as it involves me having to query the database before actually updating the object which seems unnecessary.
My business objects are shared between desktop, web and mobile applications. How would you guys approach this or what is the recommended/best way forward?
Thanks
The two approaches I have used so far are as follows:
1. Store ORM Object - In this approach I get the "customer" orm object using linq and then store it as a private/protected variable in the business object. My business object properties simply get or set the underlying orm objects properties.
The big problem I have found with this approach is that once I have retrieved an orm object I also need to persist the context as you cannot fetch from one context and update in another. I either need to store the context with the object in my class ro store it globally - neither of which I like.
2. Populate Business Object - My second approach was to retrieve the customer orm object then map the properties of this object to the properties of my business object. So far so good. The problem I have found with this approach is that when saving changes, instead of updating the record based on its ID, it always inserts a record when I create a new orm object. The only way around this appears to be to query the database for the orm object first, then update it and save the changes. I don't particularly like this approach either as it involves me having to query the database before actually updating the object which seems unnecessary.
My business objects are shared between desktop, web and mobile applications. How would you guys approach this or what is the recommended/best way forward?
Thanks