ObjectDatasource Entityframework multipletables

3 posts, 1 answers
  1. Shakti SIngh Dulawat
    Shakti SIngh Dulawat avatar
    89 posts
    Member since:
    Oct 2009

    Posted 07 Aug 2012 Link to this post

    I am using Entityframe work in my project now what I am trying to do is bind a grid with objectdatasource , I have to load data from three tables.
    There are around 5-6 tables I am trying to read data from. 
    public IEnumerable<BetsDifficultToRead> GetBetsDifficultToReadsWithDetail()
                return context.BetsDifficultToReads.Include("BetToBeSettled").Include("BetToBeSettled.BetDetails").Include("BetToBeSettled.BetDetails.Meeting").Include("BetToBeSettled.BetDetails.Event").ToList();
                //var test = (from h in context.BetsDifficultToReads
                //            select new
                //            {
                //                BetsDifficultToReadId = h.BetsDifficultToReadId,
                //                BetToBeSettledId = h.BetToBeSettled.BetToBeSettledId,
                //                UserId = h.UserId,
                //                ShortName = h.BetToBeSettled.BetDetails.Select(t => t.Meeting.ShortName),
                //                Expr1 = h.BetToBeSettled.BetDetails.Select(t => t.Event.ShortName),
                //                IsStartingPrice = h.BetToBeSettled.BetDetails.Select(t => t.IsStartingPrice),
                //                Stake = h.BetToBeSettled.Stake,
                //            });

    <telerik:RadGrid ID="radGridAllBets" runat="server" Skin="Metro"
        DataSourceID="odsAllBets" CellSpacing="0" GridLines="None">
        <MasterTableView DataSourceID="odsAllBets" AutoGenerateColumns="False">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                <HeaderStyle Width="20px"></HeaderStyle>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                <HeaderStyle Width="20px"></HeaderStyle>
                <telerik:GridBoundColumn DataField="BetsDifficultToReadId"
                    FilterControlAltText="Filter BetsDifficultToReadId column"
                    HeaderText="BetsDifficultToReadId" SortExpression="BetsDifficultToReadId"
                <telerik:GridBoundColumn DataField="UserId" DataType="System.Guid"
                    FilterControlAltText="Filter UserId column" HeaderText="UserId"
                    SortExpression="UserId" UniqueName="UserId">
                <telerik:GridBoundColumn DataField="BetToBeSettled.BetDetails.Meeting.ShortName" DataType="System.String"
                    FilterControlAltText="Filter EntityState column" HeaderText="EntityState"
                    ReadOnly="True" SortExpression="Meeting.ShortName" UniqueName="Meeting.ShortName">
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
        <FilterMenu EnableImageSprites="False">
    <asp:EntityDataSource ID="edsAllBets" runat="server">
    <asp:ObjectDataSource ID="odsAllBets" runat="server" TypeName="EPOS.Web.Business.BetsDifficultToReadBL"

    Below is the table structure  but I have issue I am not able to get value of all tables column, is I am doing wrong or there is any other best way! 



  2. Answer
    Radoslav avatar
    1564 posts

    Posted 10 Aug 2012 Link to this post

    Hi Shakti,

    You can use a wide variety of custom objects as data sources for RadGrid. The only requirement is that the custom objects must implement the ITypedList, IEnumerable, or ICustomTypeDescriptor interface. RadGrid can bind to sub objects by the intuitive and simple dot(.) syntax (specified through the DataField property of declaratively bound columns). Also I am sending you a simple example based on your code. Please check it out and let me know if it helps you. Additionally could you please verify that the GetBetsDifficultToReadsWithDetail method returns a correct collection of objects and their related sub objects? You could inspect it by checking the intellisense into the VS. If the returned objects are correct you could navigate with VS intellisense to GetBetsDifficultToReadsWithDetail().ToList()[0].BetToBeSettled.BetDetails.Meeting.ShortName property.

    Looking forward for your reply.

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Shakti SIngh Dulawat
    Shakti SIngh Dulawat avatar
    89 posts
    Member since:
    Oct 2009

    Posted 16 Aug 2012 Link to this post

    I really appreciated your time and help some how I was able to get the value without view!

Back to Top