These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Use dictionary to store mapped columns instead of property
PostPosted: Wed Mar 04, 2009 11:07 pm 
Newbie

Joined: Tue Oct 04, 2005 5:42 pm
Posts: 5
Location: North Carolina, USA
Does anyone out there know how to do the following?

I would like to store values retrieved from the database with NHibernate in a dictionary instead of using a class properties. For example, let's say we have a table Employee with three fields: Id, FirstName, and LastName.

I would like to have a class as follows:

Code:
public class Employee
{
    private Int64 _id;

    public Int64 Id
    {
        get { return _id; }
        set { _id = value; }
    }
    private IDictionary<String, Object> _properties;
    public IDictionary<String, Object> Properties
    {
        get { return _properties; }
        set { _properties = value; }
    }
    public void AddProperty(String keyName, Object value)
    {
        _properties.Add(keyName, value);
    }

    public Object GetProperty(String keyName)
    {
        return _properties[keyName];
    }
}


Then, I would like for NHibernate, when retrieving/persisting the data, I would like for NHibernate to call methods (or some means) like AddProperty/GetProperty to add the values to the dictionary using the column name as the key.

Is this possible? What I am trying to accomplish is providing a generic class that doesn't need to be compiled everytime a property is added.

Thanks-in-advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 7:56 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The closest thing hibernate offers here are dynamic-components:

http://www.nhforge.org/doc/nh/en/index.html#components-dynamic

Documentation is very brief about it and I benver used it, so I can't give you more. But maybe Google can help.

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.