0

I have a ComponentOne Grid control on a WinForm Application and I'd like to bind a "LINQ Query" instead of the whole DbSet.

If I need the full DbSet the answer is here: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported Entity Framework 5

gridControl1.DataSource = context.capitulo.Local.ToBindingList();
context.capitulo.Load();

But this do not work if I want to put an order and /or a where condition like:

gridControl1.DataSource = context.capitulo.OrderBy(x => x.Id).Local.ToBindingList();
context.capitulo.Load();

Because Local is a property of DbSet and not of IQuerable. I found lots of solution for WPF but non solution for WinForms.

Community
  • 1
  • 1

2 Answers2

0
var capituloList = new ObservableCollection<capitulo>(context.capitulo.Local.OrderBy(x => x.Id));

gridControl1.DataSource = capituloList.ToBindingList();

context.capitulo.Load();
Tim.Tang
  • 3,158
  • 1
  • 15
  • 18
  • With this solution I miss binding when I add or delete one row on the grid. It works only for updating existing values. – Nazareno Aug 28 '14 at 12:30
0

You need to apply a LINQ query to a bindable collection and get another bindable collection. That is done with LiveLinq, a part of the ComponentOne suits (together with C1DataSource, there is one in ComponentOne WinForms), so you probably have it. Just use the AsLive() extension method:

gridControl1.DataSource = context.capitulo.Local.AsLive().OrderBy(x => x.Id);

To have AsLive() available, you need

using C1.WPF.LiveLinq;

(but WPF here does not mean you are using WPF, it's just a name, you are still in WinForms)