Datasource expand

8 posts, 0 answers
  1. David Pusch
    David Pusch avatar
    1 posts
    Member since:
    Feb 2010

    Posted 27 Jun 2012 Link to this post

    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>
  2. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 28 Jun 2012 Link to this post

    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.
  3. Kendo UI is VS 2017 Ready
  4. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 29 Jun 2012 Link to this post

    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.
  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 02 Jul 2012 Link to this post

    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!
  6. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 02 Jul 2012 Link to this post

    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.
  7. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 02 Jul 2012 Link to this post

    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.
  8. Robin
    Robin avatar
    46 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2012 Link to this post

    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.
  9. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 03 Jul 2012 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready