Problem with master/detail binding to Iesi collections

40 views
Skip to first unread message

Goran

unread,
Oct 3, 2011, 3:58:18 PM10/3/11
to nhusers
I am trying to do a simple master detail databinding to Invoice /
Invoice Items, and I am unable to make it work.

// part in the invoice mapping
HasMany(x => x.Items)
.KeyColumn("InvoiceId")
.Inverse()
.Fetch.Select()
.AsSet();

// part of the InvoiceItems mapping
Id(x => x.Id)
.GeneratedBy.Native();
...

References(x => x.Invoice)
.Class(typeof(InvoiceInfo))
.Not.Nullable()
.Column("InvoiceId")
.Fetch.Select();

// binding part
invoiceBindingSource.DataSource = repository.GetInvoices();
invoiceItemsBindingSource.DataSource = invoiceBindingSource;
invoiceItemsBindingSource.DataMember = "Items";

gridInvoice.DataSource = invoiceBindingSource; // DataGridView
gridInvoiceItems.DataSource = invoiceItemsBindingSource; //
DataGridView

When I start application, invoices are present correctly, and items in
first Invoice are present correctly. However, when I try to move to
second invoice item, I get the following exception:

Exception type: System.Reflection.TargetInvocationException
Message: Property accessor 'Id' on object
'NHibernate.Collection.Generic.PersistentGenericSet`1[[Model.RacunRobaPodaciInfo,
model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' threw
the following exception:'Object does not match target type.'
Source: System
Target site: System.Object GetValue(System.Object)
Stack trace: at
System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object
component)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetValue(Int32
boundColumnIndex, Int32 columnIndex, Int32 rowIndex)

And after this I receive the same exception for the first invoice
also, which was before displayed correctly. I have displayed only one
column for sake of clarity, but if I add more columns to InvoiceItems
DataGridView, I will receive the same fault for each column. Any ideas
why is this happening?

Thanks,
Goran

Goran

unread,
Oct 5, 2011, 8:49:32 AM10/5/11
to nhusers
As additionaI information, if everytime I cast currentInvoice.Items
(which is of type ISet<InvoiceItem>) to List<InvoiceItem>, then
binding work without any problem. Is there no way I can bind to Iesi
Iset<>?

Neda

unread,
Mar 23, 2012, 1:33:07 PM3/23/12
to nhu...@googlegroups.com
I encountered the same problem.
How can I cast Iset to List every time?!
Reply all
Reply to author
Forward
0 new messages