Hi - hopefully this is a problem of Simple Simon and not a hole in the code so far :-)
Setting the scene:
I'm using the latest CVS version of ObjectViews with objects persisted via NHibernate. One of these objects (Sites) is one-to-one linked on a primary key with another (SiteDetails). So there's no foreign key - each record in one table has a matching record in the other with the same ID. The Sites class has a "Details" member of type SiteDetails and NHibernate is populating this correctly. I'm creating an ObjectView and setting its Datasource to an IList of the Site objects populated from NHibernate. I then set this as the DataSource for a DataGrid and that works just sweet (well done, folks - this is good code!).
My problem:
In addition to the datagrid, which displays the Site record members, I have a bunch of text fields etc which I would like to bind to the members of the Details property of the current Site in the same binding.
So I have stuff like:
ebLocation.DataBindings.Add("Text",siteview,"Details.Location");
where ebLocation is a text box, siteview is the ObjectView created on the Sites IList, Details is the member within the Sites class which is an instance of SiteDetails, and Location is a string sitting in the Details member.
The system doesn't like it - return fine from the function which does the DataBindings.Add but the whole thing dies on an argument exception - "Cannot bind to property or column Location on DataSource".
Is it me? Or is it a limitation in the current state of ObjectViews? I tried playing with ChildObjectViews but these complained (of course) because of the one-to-one: it's not a collection but a single object.
Any help you can offer would be hugely appreciated!
Cheers
Simon
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's a bit of a rough workaround:
- I was getting away with AutoGenerateColumns up to that point!
- I now have to track fields in two locations (both the Columns.Add to get the aliases AND the field databindings.add);
BUT it works and I can get on with my next challenge.
You guys ROCK!
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
AutoGenerateColumns indeed only works for 'simple' properties. Otherwise we have to reflect the entire object graph, which can lead to an objectview with a bizarre amount of columns.
You can use constants for aliases to overcome the problem where you have to define fields/aliases in multiple places. It's not the most elegant solution but it will at least reduce the number of typos here and there ;).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is why I often don't use aliases (or use an alias with the same name as the property). I find it esier to remember "Details.Location" than whatever alias I chose for it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi - hopefully this is a problem of Simple Simon and not a hole in the code so far :-)
Setting the scene:
I'm using the latest CVS version of ObjectViews with objects persisted via NHibernate. One of these objects (Sites) is one-to-one linked on a primary key with another (SiteDetails). So there's no foreign key - each record in one table has a matching record in the other with the same ID. The Sites class has a "Details" member of type SiteDetails and NHibernate is populating this correctly. I'm creating an ObjectView and setting its Datasource to an IList of the Site objects populated from NHibernate. I then set this as the DataSource for a DataGrid and that works just sweet (well done, folks - this is good code!).
My problem:
In addition to the datagrid, which displays the Site record members, I have a bunch of text fields etc which I would like to bind to the members of the Details property of the current Site in the same binding.
So I have stuff like:
ebLocation.DataBindings.Add("Text",siteview,"Details.Location");
where ebLocation is a text box, siteview is the ObjectView created on the Sites IList, Details is the member within the Sites class which is an instance of SiteDetails, and Location is a string sitting in the Details member.
The system doesn't like it - return fine from the function which does the DataBindings.Add but the whole thing dies on an argument exception - "Cannot bind to property or column Location on DataSource".
Is it me? Or is it a limitation in the current state of ObjectViews? I tried playing with ChildObjectViews but these complained (of course) because of the one-to-one: it's not a collection but a single object.
Any help you can offer would be hugely appreciated!
Cheers
Simon
Try to set the databindings to the alias instead of the property name (when you use aliases of course).
We'll have to think of a solution where you can use the property names here, because it is confusing right now.
Thanks, Martijn.
It's a bit of a rough workaround:
- I was getting away with AutoGenerateColumns up to that point!
- I now have to track fields in two locations (both the Columns.Add to get the aliases AND the field databindings.add);
BUT it works and I can get on with my next challenge.
You guys ROCK!
:-)
AutoGenerateColumns indeed only works for 'simple' properties. Otherwise we have to reflect the entire object graph, which can lead to an objectview with a bizarre amount of columns.
You can use constants for aliases to overcome the problem where you have to define fields/aliases in multiple places. It's not the most elegant solution but it will at least reduce the number of typos here and there ;).
This is why I often don't use aliases (or use an alias with the same name as the property). I find it esier to remember "Details.Location" than whatever alias I chose for it.