This is a migrated thread and some comments may be shown as answers.

ADO.NET Data Services (Astoria) binding and column filtering...

2 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kenneth Jamieson
Top achievements
Rank 1
Kenneth Jamieson asked on 13 Oct 2009, 11:11 AM

Hey all,

I have a RadGrid on a Wpf page, it is goign to be loading data from a Astoria service. Right away, we need to bind it programatically - the declarative syntax won't work since I need to do some set up.

Ideally, I would grab a data subset and do the binding directly, but there is at least one problem... Astoria (int he release bits) doesn't support Count() so I cannot bind the grid directly. In other words, I cannot...

 

var corePages = contextCore.CmsPageSet.OrderBy(p => p.Title);  
pageListGridView.ItemsSource = corePages;  

Instead I have to...

 

var corePages = contextCore.CmsPageSet.OrderBy(p => p.Title);  
pageListGridView.ItemsSource = corePages.ToList(); 

Which is seriously suboptimal because it means grabbing all the records over the wire to project them into the list so that the grid is happy with them. Ugly, ugly, ugly.

It gets even worse because since this is not the astoria CTP2, I can't do projections on the server, either which means I pull down all the columns for each record, even though I only need three for the grid. I need Id, Title and Sortweight. Of those, I need Id to be hidden, so that I can access it as a key when a user clicks on a row (I need to pull up a window for the edit) but the user is not bothered with it in the grid proper.

So here are my questions....

  1. Has anyone managed a direct bind between a RadGridView and an astoria data service - am I barking up the wrong tree?
  2. How do you give the RadGridView a list of columns to use from a programtically bound data source? I knwo how to declare the columns, but I am unsure how to tie them to the (future) properties of the anonymous type I will be binding after the projection. UniqueName didn't seem to be enough. The documentation is very weak in this reguard.
  3. By any chance, does someone know the proper syntax for a lambda style .Select LINQ statement to pull multiple columns out?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 13 Oct 2009, 01:25 PM
Hello Kenneth,

Find my answers in order:
  1. The problem with direct Astoria entities as grid's ItemsSource is that the Astoria client is creating an IQueryable collections. As you may know with Q2 release the grid is using LINQ to shape its data and thus pushing all data operation down to the IQueryProvider. Unfortunately Astoria's (v1) support for query transformation is very limited compared to the LINQ to SQL/Entities. This is why you need to call ToList() on your collection and eagerly enumerate it. One solution for this will be RIA Services, but they are not there yet for WPF.
  2. You should set the DataMemberBinding of the GridViewDataColumn that you are adding dynamically for your new objects. The Path of the binding should point to the specific property you want to display.
  3. If I have understand your question you want to data bind to a projection of the data that is on the client you should do it after you have called the ToList(). Here is a sample:
pageListGridView.ItemsSource = contextCore.CmsPageSet.OrderBy(p => p.Title).ToList().Select(p => new {p.ID, p.Title, p.Sortweight}).ToList();

Hope this helps.
Kind regards,
Stefan Dobrev
the Telerik (Wizard) team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 21 Oct 2009, 09:47 AM
Thanks by the way, your answer was fine - fortunatel now wth Astoria CTP2 less work i needed :)
Tags
GridView
Asked by
Kenneth Jamieson
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Kenneth Jamieson
Top achievements
Rank 1
Share this question
or