iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I am using the ClientBinding_VirtualGroupPaging_WebService Example. My scenario requires that I join 2 tables in order to get the necessary data for my grid.
With a single table I have no issues. When joining tables I am not sure of what object to use in the Provider declaration (basically how should I fill the "???" in: WebGridDataProvider<???>).
Below is my code for 1) Single table and 2) join.
[WebMethod] public object GetPagedBugs(DataSourceSelectArguments selectArguments) { BugTrackerModelDataContext context = new BugTrackerModelDataContext(); context.DeferredLoadingEnabled = false; // 1) Single table works great var datasource = from b in context.Bugs select b; WebGridDataProvider<Bug> provider = new WebGridDataProvider<Bug>(datasource); // ----------------------------------------- // 2) How to join? var datasource2 = from b in context.Bugs join o in context.Owners on b.BugId = o.BugId select new { b.BugId, b.Summary, o.OwnerName }; WebGridDataProvider<???> provider = new WebGridDataProvider<???>(datasource); // ----------------------------------------- object data = provider.Select(selectArguments); if (data != null) return data; throw new InvalidOperationException("Unsupported operation type!"); }
Under such scenario, you will be required to create a new class to hold the new object. In my sample, I create a BugCustom class that will allow me to hold the new property. Here is the snippet:
Class definition
public class BugCustom{ public int BugId { get; set; } public string Summary { get; set; } public string OwnerName { get; set; }}
Select function (I do not have the Owners table, the select is simulated to return row with 3 column)
[WebMethod]public object GetPagedBugsCustom(DataSourceSelectArguments selectArguments){ BugTrackerModelDataContext context = new BugTrackerModelDataContext(); context.DeferredLoadingEnabled = false; var datasource2 = from b in context.Bugs select new BugCustom { BugId = b.BugId, Summary = b.Summary, OwnerName = "TestOwner" }; WebGridDataProvider<BugCustom> provider = new WebGridDataProvider<BugCustom>(datasource2.AsQueryable()); object data = provider.Select(selectArguments); if (data != null) return data; throw new InvalidOperationException("Unsupported operation type!");}
The WebGrid client binding setting property
<ClientBindingSettings DataLoadMode="PagedData" DataSourceType="WebService" PreloadGroupTotals="true" ItemTypeName="BugCustom" ServiceUrl="WebService.asmx" EnableGroupRowPaging="true" GroupRowPageSize="20"> <ServiceMethods SelectMethod="GetPagedBugsCustom" /></ClientBindingSettings>
The only way I could make it work is by using this query
var datasource = from b in context.Bugs join o in context.Owners on b.BugId equals o.BugId into tl_j from j in tl_j.DefaultIfEmpty() select new BugWithOwner { BugId = b.BugId, ChangeInLast = b.ChangeInLast, Component = b.Component, Dupe = b.Dupe, OpSys = b.OpSys, Severity = b.Severity, Summary = b.Summary, Target = b.Target, OwnerId = j == null ? -1 : j.OwnerId, OwnerName = j == null ? "--" : j.OwnerName };
Hi Glenn,
That solved my issue with the join - thanks! I now have a follow up issue. I am using a left join, so some of the columns contain "Null" values. I attempted to use a default values class to replace the Nulls. Unfortunately, I am getting an error.
The attached sample shows the error.
Can you take a look?Thanks,Dave
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname