simon831 wrote:
Otis wrote:
Could you provide a stacktrace where the error originates ?
Sorry, had to do some serious re-writing to get round this.
Whats the recommended way to do this?
You could get away with the way you're doing it, except you're sending the entity over the wire. When that happens you're out of luck, because what will happen on the client when some code reads 'Price' ? Then the adapter is created but the database isn't available on the client (obviously).
So typically, you would do something like this:
- add a private member variable _price
- add a method called CalculatePrice(adapter);
In that method, you calculate the price value and set _price to that value
the property Price returns the _price value.
On the service side, you call CalculatePrice and the entity's Price property will have the value it needs.
When the entity is serialized to the client, the property will have a value and everything is good, when the property is READ on the CLIENT, no database access is possible and also not needed.
The PROBLEM is simply that you use the same entity on the client and on the service and reading the property makes a difference on the service than on the client because on the client you just want to read the Price value the entity has, not the value read from the database because you don't have db access on the client.
I need a property on an Entity in a partial class that fetches other entities from the database in order to calculate its own value.
Is this designed to be possible?
It's the never ending DDD discussion: should a domain object know about repositories of related aggregate roots / domain objects?
I'd say: no. If this necessity is there, call into a static class which will do the price fetching for you and on the client this method simply returns null so you should keep the value you have.