Hi David!

Are you sure, you have a NotaRow table in your database?

Could you post the whole exception/stack-trace here?


Tapio


On Wed, Mar 11, 2009 at 9:30 AM, David Perfors <[email protected]> wrote:

> Thanks, I did found that, and thought I got the same exception, but I
> didn't. Now I get:
> "Could not insert NotaRow: Invalid object name NotaRow"
>
> So I guess there is something wrong with my mapping, any idea?
>
> David
>
> 2009/3/10 Tapio Kulmala <[email protected]>
>
> Hi!
>>
>> You are assigning the id only in your default constructor.
>>
>> Tapio
>>
>> On Tue, Mar 10, 2009 at 1:29 PM, David Perfors <[email protected]>wrote:
>>
>>>
>>> Hello,
>>>
>>> I have two classes: one that inherits from Dictionary<> and which add
>>> some extra funtionality, and one that uses it like this:
>>>
>>> public class Distribution<T> : Dictionary<T, Decimal>, IComparable<T>
>>> {
>>> }
>>>
>>> public class NotaRow
>>> {
>>>    public NotaRow()
>>>    {
>>>        Children = new Distribution<NotaRow>();
>>>        Id = Guid.NewGuid();
>>>    }
>>>
>>>    public NotaRow(String description, Decimal toPay)
>>>    {
>>>        Description = description;
>>>        ToPay = toPay;
>>>    }
>>>
>>>    public Guid Id { get; private set; }
>>>    public String Description { get; set; }
>>>    public Decimal ToPay { get; set; }
>>>
>>>    public Distribution<NotaRow> Children { get; private set; }
>>>
>>>    public void Distribute(IEnumerable<Decimal> percentages)
>>>    {
>>>        foreach (Decimal percentage in percentages)
>>>        {
>>>            NotaRow row = new NotaRow(Description, ToPay *
>>> percentage);
>>>            Children.Add(row, percentage);
>>>        }
>>>    }
>>> }
>>>
>>> I try to map the NotaRow class to a database with the following
>>> mapping:
>>> <class name="NotaRow">
>>>  <id name="Id" type="Guid">
>>>    <generator class="assigned" />
>>>  </id>
>>>  <property name="Description" />
>>>  <property name="ToPay" />
>>>  <map name="Children">
>>>    <key column="Id" />
>>>    <index column="NotaRowId" type="Guid" />
>>>    <element column="Distribution" type="Decimal" />
>>>  </map>
>>> </class>
>>>
>>> Of course I get an error that the map is not working since I don't use
>>> any interface and only a custom dictionary type. So for ease I replace
>>> the Distribution class with the IDictionary<>/Dictionary combination.
>>> But still NHibernate is complaining that it can't save the
>>> NotaRow.Children
>>> "Exception: Could not insert collection... The insert statement
>>> conflicted with the foreign key Id NotaRowId"
>>>
>>> Can anybody give me some advice on how to solve this challange? for me
>>> these dictionary mappings are the biggest challange this far with
>>> NHibernate. (mapping to a BindingList was not easy either, but that is
>>> already solved using custom collection types.)
>>>
>>> David.
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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