With "assigned" you should define the unsaved-value (probably we must review
what is happening with "assigned" strategy to avoid the unsaved-value).Btw
you can use the strategy "guid" or even better "guid.comb" and NH will
manage the ID for you.

2009/5/29 David Perfors <[email protected]>

>
> Hello,
>
> I am writing an export function for the application I work on and I
> want to put the exported objects to an SQLite database. I have an
> object (RateTable) that contains a IList of items (RateDefinition).
> When I add the object to one ISession, it works properly, but when I
> add it to a new ISession (from a different SessionFactory) as well, it
> won't insert the reference identifier to the RateDefinition table...
>
> public class RateTable
>    {
>        private RateTable() { }
>        public RateTable(string name)
>        {
>            Id = Guid.NewGuid();
>            Name = name;
>            Definitions = new List<RateDefinition>();
>        }
>        public Guid Id { get; private set; }
>        public string Name { get; set; }
>        public IList<RateDefinition> Definitions { get; private set; }
>
>        public RateTable AddDefintion(DateTime startDate, decimal
> rate)
>        {
>            Definitions.Add(new RateDefinition(startDate, rate));
>            return this;
>        }
>
>        public override bool Equals(object obj)
>        {
>            if (GetType() != obj.GetType())
>                return false;
>            return Equals(obj as RateTable);
>        }
>
>        public bool Equals(RateTable obj)
>        {
>            return Id.Equals(obj.Id);
>        }
>    }
> public class RateDefinition
>    {
>        private RateDefinition()
>        {
>        }
>
>        public RateDefinition(DateTime startDate, decimal rate)
>        {
>            Id = Guid.NewGuid();
>            StartDate = startDate;
>            Rate = rate;
>        }
>
>        public Guid Id { get; private set; }
>        public DateTime StartDate { get; set; }
>        public decimal Rate { get; set; }
>    }
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping assembly="ImportExport"
>                   default-cascade="save-update"
>                   default-lazy="false"
>                   namespace="ImportExport.Domain"
>                   xmlns="urn:nhibernate-mapping-2.2">
>  <class name="RateDefinition">
>    <id name="Id" type="Guid">
>      <generator class="assigned" />
>    </id>
>    <property name="StartDate" />
>    <property name="Rate" />
>  </class>
>
>  <class name="RateTable">
>    <id name="Id" type="Guid">
>      <generator class="assigned" />
>    </id>
>    <property name="Name" />
>    <list cascade="save-update" name="Definitions" lazy="false">
>      <key column="RateTableId" />
>      <index column="idx" />
>      <one-to-many class="RateDefinition" />
>    </list>
>  </class>
> </hibernate-mapping>
>
> Any ideas?
>
> David
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to