views:

36

answers:

1

I have one list that contains Student informations

lsStudents = context.GetTable<Student>().Where(p => p.M_Id.Equals(1)).ToList();

And I have another one that contains Student Lessons

lsMarks = context.GetTable<Mark>().Where(p => p.M_StudentId.Equals(1)).ToList();

I want to merge these lists to one ObjectDataSource to bind to a repeater.

<asp:Repeater ID="rpt" runat="server">
    <ItemTemplate>
        <div><% Databinder.Eval(Container.DataItem,"M_StudenName") %></div>
        <div><% Databinder.Eval(Container.DataItem,"M_Mark") %></div>
    </ItemTemplate>
</asp:Repeater>
A: 

You could join the two on the id field and select out the fields of interest into a new, anonymous type.

var lsStudentWithMarks = context.GetTable<Student>().Where( p => p.M_id.Equals(1))
                                .Join( context.GetTable<Mark>().Where( p => p.M_StudentId.Equals(1), (o,i) => o.M_Id == i.M_StudentId, (o,i) => new { o.M_StudentName, i.M_Mark } )
                                .Select( j => new { j.M_StudentName, j.M_Mark } )
                                .ToList();
tvanfosson