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

ObjectDatasource Entityframework multipletables

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shakti SIngh Dulawat
Top achievements
Rank 1
Shakti SIngh Dulawat asked on 07 Aug 2012, 07:22 PM
Friends,
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>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn DataField="BetsDifficultToReadId"
                DataType="System.Int32"
                FilterControlAltText="Filter BetsDifficultToReadId column"
                HeaderText="BetsDifficultToReadId" SortExpression="BetsDifficultToReadId"
                UniqueName="BetsDifficultToReadId">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="UserId" DataType="System.Guid"
                FilterControlAltText="Filter UserId column" HeaderText="UserId"
                SortExpression="UserId" UniqueName="UserId">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="BetToBeSettled.BetDetails.Meeting.ShortName" DataType="System.String"
                FilterControlAltText="Filter EntityState column" HeaderText="EntityState"
                ReadOnly="True" SortExpression="Meeting.ShortName" UniqueName="Meeting.ShortName">
            </telerik:GridBoundColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>
<asp:EntityDataSource ID="edsAllBets" runat="server">
</asp:EntityDataSource>
<asp:ObjectDataSource ID="odsAllBets" runat="server" TypeName="EPOS.Web.Business.BetsDifficultToReadBL"
    SelectMethod="GetBetsDifficultToReadsWithDetail"
    OldValuesParameterFormatString="original_{0}"></asp:ObjectDataSource>


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! 

http://s10.postimage.org/l9eufbvt5/Capture.jpg

Thanks,
Shakti










2 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 10 Aug 2012, 07:29 AM
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,
Radoslav
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.
0
Shakti SIngh Dulawat
Top achievements
Rank 1
answered on 16 Aug 2012, 06:53 PM
I really appreciated your time and help some how I was able to get the value without view!

Thanks,
Shakti
Tags
Grid
Asked by
Shakti SIngh Dulawat
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Shakti SIngh Dulawat
Top achievements
Rank 1
Share this question
or