我正在使用 EF 代码优先模型开发 asp.net mvc 4 web api。我有一个具有导航属性的类,例如,
public class Branch
{
[Key]
public int Id{get; set;}
public List<book> books{get; set;}
}
我的书课就像,
public class book
{
[Key]
public int id{get; set;}
public string Name{get; set;}
}
现在我需要获取分支列表,所以我这样写,
public IQuerable<branch> GetBranches(int branchid)
{
return context.school.where(m=>m.id==branchid).ToList().AsQuerable();
}
现在我想将一些数据分配给分支类中的 book 属性,所以喜欢,
context.school.ToList().ForEach(m=>m.books=GetBooks(branchid));
现在要获得分支,我有类似的网址,
/api/branch/12
有什么方法可以使用像这样的 url 在特定分支中获取特定书籍
/api/branch/12/book/567
归还第 12 号分行的第 567 号书。请指导我。