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

2010 SL 4 WCF RIA Service, binding, ASP.NET website

3 Answers 89 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dean Wyant
Top achievements
Rank 1
Dean Wyant asked on 20 Jan 2011, 08:58 PM

I have looked at lots of demos / tutorials / docs and examples but I still do not know what approach to take for data access from a SL app embeded in an existing ASP.NET WebSite using LinqToSQL with table hadler classes. There seems to be multiple ways to create and access the service.

It seems that adding a "Domain Service" to the WebSite is the way to go because the SL app gets generated code that code has a copy of the LinqToSQL row classes for each table.

The RadGridView is supposed to be able to access the service and only transfer the visible data from the server.
I have not been able to succesfully bind the RadGridView.

Here is what I have:

WebSite - The ASP.NET site that contains a generated page that contains the SL app.
DataHandler - a project containing the LinqToSql dbml and other data access classes.
SL - the SL app that gets the generated code for the service.

The solution compliles fine and the SL Generated_Code folder gets the WebSite.g.cs file generated OK.

WebSite.g.cs contains:
  namespace SL, class WebContext : WebContextBase
  namespace WebSite.Services, class DS : DomainContext containing:
    Constructors, methods returning InvokeOperation, a interface IDSContract with BeginGet... and EndGet methods, a DSEntityContainer : EntityContainer class.
  namespace DataHander, class TableRow : ComplexObject (a dbml class copy)

WebSite/Services/DS.cs:
 

[EnableClientAccess()]
  public class DS : DomainService
  {
    public IEnumerable<TableRow> GetTableRows()
    {
      TableRowHandler H = new TableRowHandler();
      return H.GetRecords();
    }
  }

The above is the custom code I added to query the records. I used this code because we use table handler classes that use a context factory. I can create and access the context in code, but it is not something I can specify in xaml or as a property.

The RadGridView needs an ItemSource for binding and I do not know what to supply. 
I do not understand the DomainContext setting for the DomainDataSource.
Most examples use NorthwindDataContext or something similar.
I would think that the SL generated code class DS : DomainContext should be used, but I do not know how to access/reference it.

<UserControl x:Class="SL.MainPage"
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" 
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
  >
  
  <Grid x:Name="LayoutRoot">
    <riaControls:DomainDataSource Name="DS" QueryName="GetTableRows"  FilterOperator="Or" AutoLoad="True" LoadedData="DS_LoadedData" >
      <riaControls:DomainDataSource.DomainContext>
      <"!!!WHAT DO I PUT HERE?!!!" />
      </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>
    <telerik:RadGridView  Name="RGV" IsReadOnly="True" ItemsSource="{Binding Data, ElementName=DS}">
  </Grid>
</UserControl>

I bet this is very simple, but I have not found the answer anywhere.
I wanted to put DS for "!!!WHAT DO I PUT HERE!!!", but that is invalid. I tried adding a clr-namespace reference above and using namespace:DS, but that was unrecognized also.
Is it supposed to be some DomainContext from the WebSite? How can that work?

I would appreciate any guidance available.
Thanks.





3 Answers, 1 is accepted

Sort by
0
Dean Wyant
Top achievements
Rank 1
answered on 20 Jan 2011, 10:32 PM
Follow up:

Using the code behind (MainPage.xaml.cs) I can set the DomainDataSource.DomainContext to the generated DomainContext. However, I get SL error 4004 - Could not find matching query method or Type DS does not expose a method called 'GetTableRows"

There is a GetTableRows method in the DS : DomainContext class in the WebSite.g.cs file.
/// <summary>
/// Asynchronously invokes the 'GetTableRows' method of the DomainService.
/// </summary>
/// <returns>An operation instance that can be used to manage the asynchronous request.</returns>
public InvokeOperation<IEnumerable<TableRow>> GetTableRows()
{
    this.ValidateMethod("GetTableRows", null);
    return ((InvokeOperation<IEnumerable<TableRow>>)(this.InvokeOperation("GetTableRows", typeof(IEnumerable<TableRow>), null, true, null, null)));
}

The MainPage.xaml just had the Grid - LayoutRoot and no controls.
MainPage.xaml.cs
using WebSite;
using WebSite.Services;
using Telerik.Windows.Controls;
  
namespace SL
{
  public partial class MainPage : UserControl
  {
    public MainPage()
    {
      InitializeComponent();
      DS ctx = new DS(); // DS is the DomainContext class generated in SL/Generated_Code/WebSite.g.cs
      DomainDataSource DDS = new DomainDataSource();
      DDS.Name = "DS";
      DDS.PageSize = 10;
      DDS.AutoLoad = true;
      DDS.DomainContext = ctx;
      DDS.QueryName = "GetTableRows";
        
      RadGridView RGV = new RadGridView();
      RGV.Name = "RGV";
      RGV.IsReadOnly = true;
      RGV.ItemsSource = DDS;
  
      LayoutRoot.Children.Add(RGV);
    }
  
  }
}

Obviously I do not understand how to bind on the client. Am I trying to use the wrong DomainContext?
What am I doing wrong?


0
Dean Wyant
Top achievements
Rank 1
answered on 21 Jan 2011, 05:01 PM
Another Follow Up:

In my LinkToSQL dbml, I have added some views (instead of tables).
The main problem here is that TableRow ended up in a view instead of a table.
It seems that LinqToSql designer and Domain Service do not work well together to support views.
The code generation etc. did not output any errors, it just did not generate an EntitySet method for binding to.
I seem to have a nack for trying to do things that are difficult or unsupported.

I still am not sure how to set the DomainContext in the xaml (if I wanted to).

0
Rossen Hristov
Telerik team
answered on 24 Jan 2011, 09:54 AM
Hi Dean Wyant,

This may be off-topic, but have you considered using RadDomainDataSource. Here are the release notes:

Due to the unplanned for increase in interest in development of Silverlight line of business applications, we are making our latest addition to our Silverlight suite available before our next major release so we can enable our clients to focus on delivering their great applications without worrying about any “plumbing”. Our new Domain Data Source components ensure seamless integration between Telerik data source controls and WCF RIA Services. Now all the powerful data-shaping features of Telerik RadControls can directly translate to your domain service – filtering and sorting operations, for example, are performed directly on the server with minimum development effort. Our Domain Data Services support includes both a component that you can embed in your Silverlight page and a CollectionView Implementation that you can use in your view models for a truly MVVM-enabled scenario.
To explore the new RadDomainDataSource control in greater depth, please check its online examples and take a look at the following blog posts:
If you decide to stick to Microsoft's DomainDataSource, my suggestion would be to explore the WCF RIA Services forums.

Kind regards,
Ross
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
General Discussions
Asked by
Dean Wyant
Top achievements
Rank 1
Answers by
Dean Wyant
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or