私は、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();
}
今、ブランチクラスのブックプロパティにデータを割り当てたいので、
context.school.ToList().ForEach(m=>m.books=GetBooks(branchid));
そして今、ブランチを取得するために、次のようなURLがあります。
/api/branch/12
次のようなURLを使用して、特定のブランチで特定の本を取得する方法はありますか
/api/branch/12/book/567
12番支店の567冊を返却してください。