8,497
社区成员
发帖
与我相关
我的任务
分享
public class BlogPost
{
public int BolgID
{
get;
set;
}
public int ID
{
get;
set;
}
public string Title
{
get;
set;
}
public virtual ICollection<Category> Category
{
get;
set;
}
}
public class Category
{
public int ID
{
get;
set;
}
public string Title
{
get;
set;
}
public virtual ICollection<BlogPost> BlogPost
{
get;
set;
}
}
using(MyDemoContext context = new MyDemoContext())
{
DbSet<BlogPost> post = context.Set<BlogPost>();
var v = post.Include(p=>p.Category).Where(p=>p.ID==5).ToList();
Repeater1.DataSource = v;
Repeater1.DataBind();
}
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table>
<thead>
<td>BlogID</td>
<td>BlogTitle</td>
<td>CategoryTitle</td>//Category's title
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("ID")%></td>
<td><%# Eval("Title")%></td>
<td><%# Eval("")%></td>//这里怎么绑定 Category.Ttitle?
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
BlogID BlogTitle CategoryTitle
5 test C#, asp.net,技术
BlogID BlogTitle CategoryTitle
5 test C#
5 test asp.net
5 test 技术