Does ORM tools work with datagrids or data bindings?

A

AliRezaGoogle

Hi
As I know ORM tools encapsulate table rows in objects. In other words
we do not see rows or columns, instead we see objects with properties.
But there are some GUI components that work with dataTables and
dataRows. As an example a datagrid. A datagrid needs a dataSet or
dataTable to show it's content. However my question is about these
components. Working with ORM tools (like NHibernate) how can I feed
objects (which are managed by ORM tool) to a datagrid? How can I even
bind them to a textbox?
If you give me an article about this matter, I will be very thankfull.


Regards
 
J

Jon Skeet [C# MVP]

As I know ORM tools encapsulate table rows in objects. In other words
we do not see rows or columns, instead we see objects with properties.
But there are some GUI components that work with dataTables and
dataRows. As an example a datagrid. A datagrid needs a dataSet or
dataTable to show it's content. However my question is about these
components. Working with ORM tools (like NHibernate) how can I feed
objects (which are managed by ORM tool) to a datagrid? How can I even
bind them to a textbox?
If you give me an article about this matter, I will be very thankfull.

No, DataGrids don't require DataTables. They can use plain lists etc.

I can't say I've done much data binding, but I'd certainly expect it
to work with entities. Note that WPF data binding is significantly
different to Windows Forms databinding, I believe. Not sure how
ASP.NET fits in :)

Jon
 
M

Marc Gravell

No, DataGrids don't require DataTables. They can use plain lists etc.

Indeed. There are a range of common interfaces etc that any
implementation can support, both for collections (IList [with typed
indexer], IListSource, IBindingList, IBindingListView, ITypedList) and
entities (ICustomTypeDescriptor, TypeDescriptionProvider).

But as Jon says - even a simple array / List<T>, ArrayList will
satisfy the most basic binding requirement (IList). For more complex
scenarios there is BindingList<T>. I have created full implementations
of bindable entities / collections with dynamic properties (alon a
property-bag model), and although lengthy, it isn't all that complex.

Note that for binding purposes, PropertyDescriptor (via
TypeDescriptor.GetProperties) rules - and the framework automatically
provides a reflection-based implementation of this, so you get the
class properties. DataTable / DataRow provide an *alternative* model,
but this is, when you think about it, the exception - not the other
way around.

But if you have a specific question, let me know; I've done *lots* in
this area!

Marc
 
F

Frans Bouma [C# MVP]

AliRezaGoogle said:
As I know ORM tools encapsulate table rows in objects. In other words
we do not see rows or columns, instead we see objects with properties.
But there are some GUI components that work with dataTables and
dataRows. As an example a datagrid. A datagrid needs a dataSet or
dataTable to show it's content. However my question is about these
components. Working with ORM tools (like NHibernate) how can I feed
objects (which are managed by ORM tool) to a datagrid? How can I even
bind them to a textbox?
If you give me an article about this matter, I will be very thankfull.

A grid doesn't need a datatable, if it does the grid is seriously bad
and I'd get one from a competitor.

Most O/R mappers embed databinding interfaces in the entity classes,
either through code generation or at runtime through subclassing.
(ITypedList, IBindingList, IListSource, INotifyPropertyChanged... )

We for example implement all databinding interfaces in our entities
and binding them to a control is therefore easy, both at design time
and at runtime, be it an empty collection (so you still get columns to
appear in a grid) or a filled collection, entity etc.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

AliRezaGoogle said:
Hi
As I know ORM tools encapsulate table rows in objects. In other words
we do not see rows or columns, instead we see objects with properties.
But there are some GUI components that work with dataTables and
dataRows. As an example a datagrid. A datagrid needs a dataSet or
dataTable to show it's content. However my question is about these
components. Working with ORM tools (like NHibernate) how can I feed
objects (which are managed by ORM tool) to a datagrid? How can I even
bind them to a textbox?
If you give me an article about this matter, I will be very thankfull.

Take a look at Subsonic also, I'm been using it recently and I found it
very useful
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top