-->
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.  [ 1 post ] 
Author Message
 Post subject: NHibernate mapping domain - "extending with properties"
PostPosted: Sun Aug 01, 2010 9:07 am 
Newbie

Joined: Sun Aug 01, 2010 9:03 am
Posts: 1
Hi,

I would like to "extend" my domain classes without having to add data to the domain classes themselves. Concider I have the following class:

public class Person
{
public virtual int Id { get; private set; }
public virtual string Name { get; set; }
}

And I have the following table in the database:

tblPersons
---------------
Id integer
Name varchar(50)
CreatedBy varchar(50)
CreatedDate datetime

So I don't want to add "CreatedBy" and "CreatedDate" to my domain class, because this has nothing to do with the actual domain itself...

Would it be possible to get this data whenever I load an entity? I would like to use it like this:

Person person = session.Load(1);

person.CreatedBy(); <-- CreatedBy is an Extension function... doesn't really matter how I access the CreatedBy value... as long as I don't have to add it to the Person class
person.CreatedDate(); <-- CreatedDate is an Extension function... doesn't really matter how I access the CreatedDate value... as long as I don't have to add it to the Person class

Can anyone point me in which direction to go in order to implement this?

I have thought about the following possibilities:

* Implementa a custom ProxyFactory, where I inject a custom "interface" such as IUpdateable, howver it seems like NHibernate doesn't create the proxies consistently, sometimes it loads a my "proxy class" class, and sometimes it loads the "normal class":

Person person = session.Load(2); //this will load my Proxy class of Person just fine

Address address = person.Address; //Somehow this doesn't load a Proxy for Address, but instead loads it normally - seems like it's evaluating "ImmediateLoad", which doesn't load proxies, due to lazy loading... not sure how to make this behave as I want.

*Using a custom PropertyAccessor, I have read something about this - but it seems I must actually map this to a property that EXITS on the domain class... so that wouldn't work right?

*Just as NHibernate "injects" code to the runtime when creating the Proxy classes - perhaps I could do the same but inject the "interface" to the original Person class instead?

Would appreciate any help on this, thank you! :)


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

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.