views:

16

answers:

1

Hi,

I'm using NHibernate 2.2 for my database work and I've faced an issue recently. I have a class called PrescDrugItem which is shown below

public class PrescDrugItem
{
    public virtual int ItemNumber { get; set; }

    [DataMember]
    public virtual int AmountIssued { get; set; }

    [DataMember]
    public virtual string TimePeriod { get; set; }
}

following is the mapping file

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly ="DataContractsLib"
               namespace="DataContractsLib.Prescription" >

  <class name="PrescDrugItem">
    <id name="ItemNumber" type="Int32">
       <generator class="native" />
    </id>
    <property name="AmountIssued" type="Int32" />
    <property name="TimePeriod" type="String" length="30" />
  </class>

my problem is, now I need to add another property to the class Item (say ItemTradeName etc), but I dont want it to be saved to the database( because I want to use this new property to store some data temporary). I tried update=false and insert=false in the mapping file but no success yet. Could you guys please tell me is this possible thing to do . Thank you.

+3  A: 

If it's not to be fetched from the database either, just add it as a normal property of your class and don't map it.

Neil Moss
thank you for replying Neil, but I thought that it creates another issue when saving the object with the newly added property ? because the nhibernate doesn't know about the property ( no entry in the mapping). I just tested some code and it seems to work very well :)
Nadun