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 virtual BlogSite BlogSite
{
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的标题
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("ID")%></td>
<td><%# Eval("Title")%></td>
<td><%# Eval("")%></td>//这里怎么绑定
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
最终显示效果就是列出这篇博客对应的多种分类:
BlogID BlogTitle CategoryTitle
5 test C#
5 test asp.net
5 test 技术
繁星点点滴滴
HUWWW
沧海一幻觉
慕田峪9158850
德玛西亚99
神不在的星期二