Thanks guys! I think I got the point! ------------------------
On 30 maio, 16:29, Gunnar Liljas <[email protected]> wrote: > A very good solution by Alexander, and having a "Block" method, instead of > a property with side effects, is much more DDD than any kind of PI. The > core part of DDD is the language, and the action is "Blocking a user", it's > not "Setting a user's IsBlocked status to true". > > I would likely keep the mapped property though, since it makes for easier > querying. > > For other cases, you can tell NHibernate to hydrate an instance (setting > property values) using different access strategies, so it's perfectly > possible to get around stuff like this. > > http://nhforge.org/doc/nh/en/index.html#mapping-declaration-property > > /G > > 2012/5/30 Alexander I. Zaytsev <[email protected]> > > > > > > > > > This is not related to NH it is about design of you 'entities'. > > > My solution to your issue to do it like following: > > > 1. Do not persist IsBlocked property: make it looks like: > > public virtual bool IsBlocked { get { return BlockDate != null; } } > > > 2. Add method Block to user, which set BlockDate: > > > public virtual void Block () { BlockDate = DateTime.Now; } > > > 3. Profit. > > > 2012/5/30 rfDelanhese <[email protected]> > > >> Hello, I´m trying to get started in the “DDD with C#” world. > >> I use NHibernate as my ORM tool, thus trying to develop a > >> PI(Persistence Ignorance) model. > >> However, in some of my entities (which are being represented as POCOS) > >> I have business rules in the setters of my properties. > >> For example, I have a “User” entity which have a flag that indicates > >> if this user is blocked or not, when this flag is true a second field > >> called “Block Date” > >> must be automatically filled whith the current date. > >> Everything seems very clear and simple, but the problem arises in the > >> moment that I´m recovering users that has already persisted in the > >> database, even though > >> the blocked users will have their “Blocked Dates” update to the > >> current date, according whit this logic. > >> Initially I thought in a second flag “isLoaded” that would indicates > >> that the object is being hydrated by NHibernate and then this logic > >> wouldn´t be launched, > >> however this didn´t seem like PI. Any suggestion on how to improve > >> this? > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "nhusers" group. > >> To post to this group, send email to [email protected]. > >> To unsubscribe from this group, send email to > >> [email protected]. > >> For more options, visit this group at > >>http://groups.google.com/group/nhusers?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "nhusers" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
