-->
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.  [ 3 posts ] 
Author Message
 Post subject: Created a calculated field
PostPosted: Tue Mar 04, 2008 11:36 am 
Newbie

Joined: Tue Mar 04, 2008 11:31 am
Posts: 1
I want to create a calculated filed based on the value of two separate fields that are strings (varchar in SQL Server). So, if field 1 has a value of "abc" and field 2 has "xyz", I want a single new field on my data object that is "abc (xyz)". I'm basically adding paranetheses around the "xyz" and joining it to "abc." I'm doing this for display purposes in an application I'm working on.

How do I do this in nHibernate?

TIA,

Ian


Top
 Profile  
 
 Post subject: Created a calculated field
PostPosted: Tue Mar 04, 2008 1:25 pm 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Ian,

I suspect there are multiple solutions to this. One solution might be to have a protected setter for your calculated field that doesn't actually do anything:
Code:

public virtual string Field1
{
    get { return _field1; }
    set { _field1 = value; }
}

public virtual string Field2
{
    get { return _field2; }
    set { _field2 = value; }
}

public virtual string CalculatedField
{
    get { return _field1 + " (" + _field2 + ")"; }
    protected set { }
}



And then map the calculated field as normal.

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 7:52 pm 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
If this is just for display purposes it sounds wrong to put the calculated field in the database at all - just leave it as an unmapped readonly property.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.