For a small frameworkish thing I wanted to make something similar to
the great functionality provided by Castle's ARDataBind attribute.

One big difference is that this is based on NHibernate model itself
and not ActiveRecord as it with Castle. For starters (not as
attribute, seperated logic)  I made a NHibernateEntityFetcher.

In a nutshell it allows you to provide a list (NameValueCollection) of
identifiers (if you have a Customer entity, which has Orders many side
and Product one side, you can provide keys for example "customer.id",
"orders", "product"), a persisted type (e.g. Customer) and a strategy
(FetchRootAndOptionallyChildren, FetchOnlyChildren,
NewInstanceIfInvalidKey, NullIfInvalidKey) by which to fetch objects.
And it depending on the strategy it will load or instantiate parent
entity, load the children by ids (if provided and strategy says it
should), connect them together (add to parent the children, add to
children the parent if needed) and return a prepared object for insert
or update.

The syntax is something like:

var fetcher = new NHibernateEntityFetcher(session);

var customer =
fetcher.Do(FetchBehavior.FetchOnlyChildren).Fetch<Customer>(keyValues);

or

var customer =
fetcher.Do(FetchBehavior.FetchOnlyChildren).Fetch(typeof(Customer),
keyValues);

and alternatevly you can provide a strategy to assemble key names (if
for example the values provided in the NameValueCollection are
composed differently then [entitytypename].[entitypropertyname]).


This all works by using the NHibernate internal class mappings and
delegates as much reflection actions as possible to NHibernate itself
(instantiating, setting property values and such which I found I could
use).


If someone would be interested in this I can write a blog post about
it and put the source and sample project online?



Cheers!
Vladan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to