分类:
public class Category
{
public int id{get;set;}
public string categoryname{get;set;}
}
内容:
public class Content
{
public int id{get;set;}
public string title{get;set;}
public string content{get;set;}
public int categoryid{get;set;}
public Category currentcategory{get;set;}
}
内容表中的categoryid是外键,指向Category的id
现在的需求是在获取内容列表时,同时也需要获取内容所属的分类,并赋值给currentcategory.
现在的 SQL是:select * from (select *,Row_Number() over(order by id desc) as rowNumber from tb_Content where categoryid=@categoryid)t where t.rowNumber>= @start and t.rowNumber<=@end
List<Content> list= conn.Query<Content>(sql,new{categoryid=categoryid,start=start,end=end}).ToList();
这样获取不到currentcategory。