Mapping unknown fields dynamically in fluent nhibernate

78 views
Skip to first unread message

Silvia

unread,
Jun 14, 2009, 10:54:04 PM6/14/09
to nhusers, sima...@gmail.com

Here is the situation:
I am using fluent nhibernate with a legacy database. I need to map
some additional columns to a dictionary(?) property in my entity
dynamically, because I do not know the number of columns and column
names and other specifications at compile time and I dynamically need
to work with those columns(insert,update...).There is another object
which has those information and has a relationship with my main entity
based on the value of two other columns.Is this possible in
nhibernate?
I tried to use DynamicComponent but the problem is I don't know what
would be the properties in my component.
I appreciate if someone could help.
Thanks

(similar problem here:
http://stackoverflow.com/questions/672840/nhibernate-map-unknown-amount-of-columns-to-dictionary/989891#989891)

Fabio Maulo

unread,
Jun 14, 2009, 11:17:16 PM6/14/09
to nhu...@googlegroups.com
Duck typing ?



2009/6/14 Silvia <sima...@gmail.com>



--
Fabio Maulo

sima ganji

unread,
Jun 15, 2009, 11:59:05 AM6/15/09
to nhu...@googlegroups.com
Thanks for your reply Fabio,but I am still not very sure how to implement this.Could you please give me more explanation?
My main entity and it's mapping is there, but I have some more fields which I need to map them dynamically.
 
Regards, 

Fabio Maulo

unread,
Jun 15, 2009, 12:10:16 PM6/15/09
to nhu...@googlegroups.com
You mean that you have a ProperyBag ? You can persist a PropertyBag using Map or Dynamic-Map how present the PropertyBag outside persistence stuff is another matter.


2009/6/15 sima ganji <sima...@gmail.com>



--
Fabio Maulo

sima ganji

unread,
Jun 15, 2009, 12:41:42 PM6/15/09
to nhu...@googlegroups.com
Something like this:
In Entity.cs I have this
public virtual IDictionary AdditionalFields { get; set; }
public virtual  Info AdditionalFieldsInfo{get; set;}
 
In EntityMap.cs I have this

References(x => x.AdditionalFieldsInfo);

and I should have something like this:

DynamicComponent(x => x.AdditionalFields , m =>

{

m.Map(?I dont have the number of columns to be mapped and column names.These information needs to come from AdditionalFieldsInfo);

});

Regards,

 

sima ganji

unread,
Jun 15, 2009, 1:40:32 PM6/15/09
to nhu...@googlegroups.com
I explained the situation in my previous post.Any thought how to do this mapping?

Silvia

unread,
Jun 15, 2009, 10:28:02 PM6/15/09
to nhusers
Yes, it would be a propertybag.The example that I mentioned is in
fluent nhibernate,but it is also fine for me to know how to fix it in
nhibernate xml mapping.The problem with component or dynamic component
is that I need to specify the properties which I do not know and I
will have the information at run time.That is why I need to map them
dynamically.
I also posted the same question in fluent nhibernate user group and
hope to get some answers in any of the groups.
Thanks.


On Jun 15, 1:40 pm, sima ganji <simaga...@gmail.com> wrote:
> I explained the situation in my previous post.Any thought how to do this
> mapping?
>
>
>
> On Mon, Jun 15, 2009 at 12:41 PM, sima ganji <simaga...@gmail.com> wrote:
> > Something like this:
> > In Entity.cs I have this
> > public virtual IDictionary AdditionalFields { get; set; }
> > public virtual  Info AdditionalFieldsInfo{get; set;}
>
> > In EntityMap.cs I have this
>
> > References(x => x.AdditionalFieldsInfo);
>
> > and I should have something like this:
>
> > DynamicComponent(x => x.AdditionalFields , m =>
>
> > {
>
> > m.Map(?I dont have the number of columns to be mapped and column
> > names.These information needs to come from AdditionalFieldsInfo);
>
> > });
>
> > Regards,
>
> > On Mon, Jun 15, 2009 at 12:10 PM, Fabio Maulo <fabioma...@gmail.com>wrote:
>
> >> You mean that you have a ProperyBag ? You can persist a PropertyBag using
> >> Map or Dynamic-Map how present the PropertyBag outside persistence stuff is
> >> another matter.
>
> >> 2009/6/15 sima ganji <simaga...@gmail.com>
>
> >>  Thanks for your reply Fabio,but I am still not very sure how to
> >>> implement this.Could you please give me more explanation?
> >>> My main entity and it's mapping is there, but I have some more fields
> >>> which I need to map them dynamically.
>
> >>> Regards,
>
> >>>  On Sun, Jun 14, 2009 at 11:17 PM, Fabio Maulo <fabioma...@gmail.com>wrote:
>
> >>>> Duck typing ? Possible:
> >>>>http://fabiomaulo.blogspot.com/2008/10/less-than-gof-is-hbm.html
>
> >>>> 2009/6/14 Silvia <simaga...@gmail.com>
>
> >>>>> Here is the situation:
> >>>>> I am using fluent nhibernate with a legacy database. I need to map
> >>>>> some additional columns to a dictionary(?) property in my entity
> >>>>> dynamically, because I do not know the number of columns and column
> >>>>> names and other specifications at compile time and I dynamically need
> >>>>> to work with those columns(insert,update...).There is another object
> >>>>> which has those information and has a relationship with my main entity
> >>>>> based on the value of two other columns.Is this possible in
> >>>>> nhibernate?
> >>>>> I tried to use DynamicComponent but the problem is I don't know what
> >>>>> would be the properties in my component.
> >>>>> I appreciate if someone could help.
> >>>>> Thanks
>
> >>>>> (similar problem here:
>
> >>>>>http://stackoverflow.com/questions/672840/nhibernate-map-unknown-amou...
> >>>>> )
>
> >>>> --
> >>>> Fabio Maulo
>
> >> --
> >> Fabio Maulo- Hide quoted text -
>
> - Show quoted text -

Fabio Maulo

unread,
Jun 15, 2009, 10:51:40 PM6/15/09
to nhu...@googlegroups.com
When I wrote Map I mean this map:

You can use it as a name-value list.

2009/6/15 Silvia <sima...@gmail.com>



--
Fabio Maulo

sima ganji

unread,
Jun 16, 2009, 9:23:59 AM6/16/09
to nhu...@googlegroups.com
The problem is how to Map or Dynamic Map when the the columns inside the bag are unknown, or how can I map a collection of unknown properties inside a property bag of an entity?
in other explanation in Entity.cs I have:
 
public virtual IDictionary AdditionalFields { get; set; }(supposed to be my additional unknown fields)
public virtual  Info AdditionalFieldsInfo{get; set;}(another object which has the information about AdditionalFields or unknown fields)
 
in mapping file I have:

<

many-to-one name="AdditionalFieldsInfo"

class="Info"

/>

<dynamic-component name="AdditionalFields">
(The problem is here:The number of properties to be mapped are unknown and also the column names and other spec.)

<property name=type?>

<property name=type?>

 </dynamic-component>


So how can I map those fields dynamically?

Thanks.

 

Fabio Maulo

unread,
Jun 16, 2009, 9:41:33 AM6/16/09
to nhu...@googlegroups.com
AdditionalField shoud be mapped as <map>


2009/6/16 sima ganji <sima...@gmail.com>



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages