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

Datasource expand

7 Answers 389 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
David Pusch
Top achievements
Rank 1
David Pusch asked on 27 Jun 2012, 10:41 AM
Hi There,

i have a oData WCF v2 pointing to an Openaccess entities set. the issue i'm having is that i'm unable to link (expand) it's relational classes within the datasource call, I get "null" and Undefined" returned when trying to call the field of the relational classes

SVC:
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [JSONPSupportBehavior]
public partial class SQZEntitiesService : OpenAccessDataService<Sequentia.SQZEntities>
{
   /// <summary>
   /// Initializes the service.
   /// </summary>
   /// <param name="config">The configuration object.</param>
   public static void InitializeService(DataServiceConfiguration config)
   {
       config.SetEntitySetAccessRule("URLs", EntitySetRights.All);
       config.SetEntitySetAccessRule("TACs", EntitySetRights.All);
       config.SetEntitySetAccessRule("Offers", EntitySetRights.All);
       config.SetEntitySetAccessRule("IncomingActivityInfos", EntitySetRights.All);
       config.SetEntitySetAccessRule("FormReportData", EntitySetRights.All);
       config.SetEntitySetAccessRule("FormData", EntitySetRights.All);
       config.SetEntitySetAccessRule("DefaultChannelTypes", EntitySetRights.All);
       config.SetEntitySetAccessRule("DecisionStages", EntitySetRights.All);
       config.SetEntitySetAccessRule("ChannelTypes", EntitySetRights.All);
       config.SetEntitySetAccessRule("ChannelInfos", EntitySetRights.All);
       config.SetEntitySetAccessRule("CaptureObjectValues", EntitySetRights.All);
       config.SetEntitySetAccessRule("CaptureObjectProperties", EntitySetRights.All);
       config.SetEntitySetAccessRule("CaptureObjects", EntitySetRights.All);
       config.SetEntitySetAccessRule("Activities", EntitySetRights.All);

       // TODO: Set service behavior configuration options
       // Examples:
       // config.DataServiceBehavior.AcceptCountRequests = true;
       // config.DataServiceBehavior.AcceptProjectionRequests = true;
       config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            
   }
}

Grid DS:
<script>
                $(document).ready(function () {
                    $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: {
                                    url: "/DesktopModules/SQZWCF/SQZEntitiesService.svc/Activities",
                                    data: {
                                        expand: "TAC,Offer"
                                    }
                                }
                            },
                            schema: {
                                model: {
                                    fields: {
                                        ActivityID: { type: "number" },
                                        TACID: { type: "number" },
                                        Date: { type: "date" },
                                        ChannelTypeID: { type: "number" },
                                        Offername: { type: "text" }
                                    }
                                }
                            },
                            pageSize: 10,
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        height: 250,
                        filterable: true,
                        sortable: true,
                        pageable: true,
                        columns: [{
                            field: "ActivityID",
                            filterable: false
                        },
                            "TACID",
                            {
                                field: "Date",
                                title: "Date",
                                width: 200,
                                format: "{0:MM/dd/yyyy}"
                            },
                            "ChannelTypeID",
                            "Offername"


                        ]
                    });
                });
            </script>

7 Answers, 1 is accepted

Sort by
0
Robin
Top achievements
Rank 1
answered on 28 Jun 2012, 08:10 PM
I too am having the same issue.  The expanded object comes back as __deferred as if I didn't expand it.
I checked the request url, and it included $epxand=Role, but the Role object was not included.
I can add ?$expand=Role on the end of my URL but that kind of defeats the purpose.

Thanks.
0
Robin
Top achievements
Rank 1
answered on 29 Jun 2012, 03:48 PM
I looked a little closer at the query being issued to the WCF data service, and it included the expand, but missed the $.
If I go copy the url, and change &expand to &$expand the data comes back like I would think it should.

?%24inlinecount=allpages&expand=Role&%24top=25 is the generated querystring.
0
Daniel
Telerik team
answered on 02 Jul 2012, 09:27 AM
Hello,

@David

The expand option should be prefixed with a dollar sign in order to be recognized by the service.

@Robin
I am not sure what is causing the problem with including the related classes. Could you provide the full code you are using or a sample project that reproduces this behavior so I can check the setup?

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Robin
Top achievements
Rank 1
answered on 02 Jul 2012, 01:17 PM
Thank you for the reply.

Here is my page I am working on.
<script type="text/javascript">
    $(document).ready(function () {
        var serviceUrl = "http://localhost:48035/Services/MyDataService.svc/UserInfoes";
        dataSource = new kendo.data.DataSource({
            type: "odata",
            transport: {
                read: {
                    url: serviceUrl,
                    dataType: "json",
                    data: {
                        expand: "Role"
                    }
                },
                update: {
                    url: function(data) {
                        return serviceUrl + "(" + data.id + ")";
                    }
                },
                create: {
                    url: serviceUrl
                },
                destroy: {
                    url: function(data) {
                        return serviceUrl + "(" + data.id + ")";
                    }
                }
            },
            batch: false,
            pageSize: 25,
            serverPaging: true,
            serverFilter: true,
            schema: {
                model: {
                    id: "id",
                    fields: {
                        id: { type: "number", editable: false },
                        logon: { type: "string", editable: false },
                        email: { type: "string", editable: false },
                        phone: { type: "string", editable: false },
                        display_name: { type: "string", editable: false },
                        name: { type: "string" }
                    }
                }
            }
        });
 
        $("#usersGrid").kendoGrid({
            dataSource: dataSource,
            editable: "inline",
            height: 400,
            filterable: true,
            sortable: true,
            groupable: false,
            pageable: true,
            columns: [{
                field: "id",
                title: "Id", 
                width: 30
            }, {
                field: "logon",
                title: "Username",
                width: 100,
            }, {
                field: "email",
                title: "Email",
                width: 150,
            }, {
                field: "phone",
                title: "Phone",
                width: 75,
            }, {
                field: "display_name",
                title: "Name",
                width: 200
            }, {
                field: "name",
                title: "Role",
                width: 100,
                //editor: roleDropDownEditor
            }, {
                command: ["edit""destroy"], title: "Actions", width: "110px"
            }]
        });
    });
 
    function roleDropDownEditor(container, options) {
        $('<input data-text-field="name" data-value-field="id" data-bind="value:' + options.field + '"/>"')
        .appendTp(container)
        .kendoDropDownList({
            autoBind: false,
            dataSource: {
                type: "odata",
                transport: {
                    read: "http://localhost:48035/Services/MyDataService.svc/Roles"
                }
            }
        });
    }
    </script>
    <div id="usersGrid">
    </div>

This is a simple listing of users in the application and their associated role.
UserInfo table has properties logon, email, phone, display_name, id and role_id which is a foreign key to the Role table which has properties id, name.
I've also created a fidle trying to reproduce the problem using odata.org's NorthwindDataService, but am having a slightly different issue.
http://jsfiddle.net/giltnerj0/BKy5m/ 
This fiddle, doesn't even append the expand=Order_Details to the URL being issued to the data service.
0
Robin
Top achievements
Rank 1
answered on 02 Jul 2012, 08:02 PM
I've created a simple test that uses a database with two tables, a WCF data service, and a single page.
I get the same issue when trying to expand the data to include the child table.
0
Robin
Top achievements
Rank 1
answered on 03 Jul 2012, 12:16 PM
Doh, I probably should have read your reply to David.
Changing to $expand seems to fix the problem

transport: {
                read: {
                    url: serviceUrl,
                    dataType: "json",
                    data: {
                        $expand: "Role"
                    }
                },


Thanks.
0
Daniel
Telerik team
answered on 03 Jul 2012, 02:33 PM
Hello again Robin,

I am glad that I could help. Regarding the problem with the parameter in the jsFiddle sample, it seems to be caused by the version which is included("2011.3.1007"). Updating it should resolve the problem.

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
David Pusch
Top achievements
Rank 1
Answers by
Robin
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or