O/R Mapping and visual controls  
Author Message
Andrei G.





PostPosted: Architecture General, O/R Mapping and visual controls Top

Hi

I'm rather new to .Net: what is the best way to link persistent domain objects with data-aware visual controls

What I'm trying to do is to use a rich domain model, get an O/R mapping tool/framework (e.g. NHibernate) to take care of persistence but still be able to use Girds and other DB controls.

Any help would be greatly appreciated.

Andrei.


Architecture3  
 
 
Lowendahl





PostPosted: Architecture General, O/R Mapping and visual controls Top

There is no problem binding domainobjects fetched with O/R mappers to visual controls AFAIK, do you have a certain scenario that have proven not to work

 
 
Andrei G.





PostPosted: Architecture General, O/R Mapping and visual controls Top

Thanks for the prompt reply Patrik.
As I said I'm rather new to .Net so perhaps the answer to my question is quite obvious...
Let's say we have a class Person
class Person
{
public String Name;
}

which has NHibernate mapping and can be loaded / persisted from/to DB. How would you get it displayed in a grid (I mean one obvious and very naive solution would be to manually load the whole table and insert it in to a Grid). It gets even more tricky if we take some 3d party Grid implementation with sorting, filtering and such.
I guess it all can be done by implementing custom DataSet, but I was wondering if that scenario has been covered by one of O/R M frameworks. The frameworks I've looked into (except for AgileStuido, which doesn't seem to be supported) do not elaborate on connecting to visual components so I've assumed they don not provide this link.

Thanks
Andrei

 
 
Lowendahl





PostPosted: Architecture General, O/R Mapping and visual controls Top

It need to be a property instead of a field. But you display it in the same way as you do with datasets. You feed the grids DataSource property with a list fo Persons and it will be displayed (for example a List<Person>)



 
 
Andrei G.





PostPosted: Architecture General, O/R Mapping and visual controls Top

Thanks Patrik. I realize I'd need a property. List<Person> would work for displaying all loaded data in a grid. But I can't imagine how sorting, filtering or even scrolling on large dataset will work. I guess (I might be terribly wrong here) that DataSets are taking care of it normally... What would you do to provide the same functionality

Once again, thanks a lot for you help. I really appreciate it.

Andrei

 
 
Lowendahl





PostPosted: Architecture General, O/R Mapping and visual controls Top

When binding to a dataset you actually bind to a tables defaultview object which is the one with capabilities of sorting and filtering.

For List<Product> there is both sort and filtering (findall) but they both use some kind of strategy object (delegegate for find and IComparable objected for sort) so using them in data binding differs a bit between windows forms and web. What are you specifically looking for



 
 
Andrei G.





PostPosted: Architecture General, O/R Mapping and visual controls Top

Hi Patrik

I'm looking for a solution for Windows Forms. I've got almost everything clear now (thanks to you). One thing that still concerns me is how sorting, filtering and scrolling would work on a large dataset. Say we have 100.000 rows in the person table - I guess the only way to sort,filter or scroll through it would be to load all 100.000 from DB Otherwise I can't imagine how to sort it using comparable. Is that right


Thanks a lot, you are a great help!

Andrei

 
 
Lowendahl





PostPosted: Architecture General, O/R Mapping and visual controls Top

If you have 100.000 records you would have the same problem with datasets that you do with List<>. You need to create the logic yourself to fetch only the data you want to display. Traditionally that is done by just calling for a subset of rows in your SQL-statement



 
 
Andrei G.





PostPosted: Architecture General, O/R Mapping and visual controls Top

But I thought that Datasets would take care of at least filtering and sorting - I mean, I would expect that it will fire a new select query to get it sorted by some column or apply a filter. That way dataset does not have to fetch all the data to sort/filter it. Am i being completely wrong here


Thanks
Andrei

 
 
Lowendahl





PostPosted: Architecture General, O/R Mapping and visual controls Top

Yes,

DataSets do not know about the store where the data came from or any additional data that is left there. Only about the data it already have in memory.