views:

340

answers:

2

I am currently working on a small N-Tier application in C# which uses Linq-to-Entities (SQL Express 2005 for the DB) and WPF and I am wondering what type of data collection my business logic layer should be supplying to the user interface.

Are there downsides (performance, validation etc) to binding form objects like datagridviews to an IQueryable? Should I populate an in-memory DataTable and pass that to the UI? In which layer should the DataContext be initialized?

+4  A: 

You can't bind properly to an IQueryable<T> (except in ASP.NET where IEnumerable<T> is fine) - it ideally wants a repeatable list of objects. Using DataTable is counter-intuitive. All you need is a List<T> / BindingList<T> etc; i.e.

var qry = ...;
var list = qry.ToList();

Now use list as the binding source.

IMO, the data-context would be hidden behind a repository interface, but your mileage may vary.

Marc Gravell
+5  A: 

To add to Marc's list, you might want to look to ObservableCollection<T> also.

EDIT: ObservableCollections are commonly used in the MVVM pattern, read about that here to see some examples.

Gerrie Schenck
Thanks, I've been reading about OCs but it's difficult to find a simple example that shows when they're useful.
Damien
Posted a link that will provide you with some examples.
Gerrie Schenck