开发者

ObjectDataSource with Composite Lists

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>
        &开发者_JAVA百科lt;div><% Databinder.Eval(Container.DataItem,"M_Mark") %></div>
    </ItemTemplate>
</asp:Repeater>


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜