Goran
unread,Oct 3, 2011, 3:58:18 PM10/3/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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