I have an objectview control over a class called OrderItem that has a Product property of class Product. Class Product has an Int32 Id property.
I mapped a column aliased Product to OrderItem.Product.Id property. When I enter a value into that column in a new row of a datagrid (an UltraWinGrid from Infragistics) and I exit that row, EndEdit is called and I receive an error:
'non-static method requires a target.'
Debugging EndEdit method I found that OrderItem.Product is null (the innerobject is an OrderItem class, but its Product property is set to null).
I found that when ObjectView.AddNew is called, the object created and assigned to the new ObjectViewRow is OK (with Product property initialized to a new Product object)
What's wrong? Is there something I'm missing?
Thanks
Marcelo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ive solved the problem using an event of the datagrid (UltraWinGrid from Infragistics) that checks value changes of the datagrid cell. If the underliying object has Product property null, I get the Product from the database using Hibernate session.Get using the id entered by the user in the cell.
In that way I've solved the problem, it is OK or is there any better mechanism?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hmm, this sounds strange, because the Product is (or at least was) properly initialized.
You mentioned NHibernate. Is it possible that some of the OrderItem or Products are proxies and some not?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you add the lazy="true" attribute to a class, NHibernate only populates the objects from the database when needed. The proxy is a run-time generated subclass of the real class that implements this behaviour.
Because the ObjectView only knows the initial type, it might be possible that it doesn't know what to do when it has to deal with a generated subclass. But I'm not sure if this is really the case because I didn't test this scenario with NHibernate yet.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have an objectview control over a class called OrderItem that has a Product property of class Product. Class Product has an Int32 Id property.
I mapped a column aliased Product to OrderItem.Product.Id property. When I enter a value into that column in a new row of a datagrid (an UltraWinGrid from Infragistics) and I exit that row, EndEdit is called and I receive an error:
'non-static method requires a target.'
Debugging EndEdit method I found that OrderItem.Product is null (the innerobject is an OrderItem class, but its Product property is set to null).
I found that when ObjectView.AddNew is called, the object created and assigned to the new ObjectViewRow is OK (with Product property initialized to a new Product object)
What's wrong? Is there something I'm missing?
Thanks
Marcelo
Ive solved the problem using an event of the datagrid (UltraWinGrid from Infragistics) that checks value changes of the datagrid cell. If the underliying object has Product property null, I get the Product from the database using Hibernate session.Get using the id entered by the user in the cell.
In that way I've solved the problem, it is OK or is there any better mechanism?
Thanks
Hmm, this sounds strange, because the Product is (or at least was) properly initialized.
You mentioned NHibernate. Is it possible that some of the OrderItem or Products are proxies and some not?
Excuse my ignorance, I'm new to Hibernate and I don't know what is a proxy.
If you add the lazy="true" attribute to a class, NHibernate only populates the objects from the database when needed. The proxy is a run-time generated subclass of the real class that implements this behaviour.
Because the ObjectView only knows the initial type, it might be possible that it doesn't know what to do when it has to deal with a generated subclass. But I'm not sure if this is really the case because I didn't test this scenario with NHibernate yet.
i'm not using proxies
Btw, is it possible to post your code or put it somewhere online so we can have a look at it?
I can't reproduce the problem. Maybe it was a problem in the object creation process of the underlaying OrderItem object.