Parts互いに特定の関係にあると呼ばれるものを持つ CRUD MVC アプリを作成しました。
PartMain      - o:m Section, o:m Report
PartSection   - m:o Main, o:m Property
PartProperty  - m:o Section, Contains MainID for sorting purposes, SortByMainID
PartReport    - m:o Main
すべてのモデルが機能しており、その部分についてはすべて問題ありません。ここで、 let say selected に関連するすべてのデータを表示するビューを生成したいと考えていますPartMain。そのようです:
PartMain: Name, Desc, etc... rest of data
    PartSection1: data...
        PartProperty1: data.. (all properties in relationship with that section)
    PartSection2: data... (all sections in relationship with selected PartMain)
        PartProperty1: data.. (all properties in relationship with that section)
    PartReport: data.... (all reports with selected PartMain)
foreachループのようなことをしなければならないことはわかっていますViewが、ロジックを理解するのに苦労しています。誰か助けてもらえますか?
ありがとう。
PartMainName および Desc プロパティを含み、 o:mPartSectionおよび o: m にも含まれますPartReport。PartSectionName および Desc プロパティを含み、 o:m にも含まれますPartProperty。PartProperty名前と説明が含まれます。PartReport名前とバージョンが含まれています。
したがって、私がやりたいことは、次のような疑似コードを使用することです。 controllerでこれを試し、viewbagでデータを渡しましたが、何も返されませんでした
pMainID = selectedMainID;
PartMain partMain = db.PartMain.Find(pMainID);
ViewBag.Name = partMain.Name
ViewBag.Desc = partMain.Desc
var partSections = db.PartSection.Where(s => s.pMainID = pMainID);
foreach (var partSec in partSections)
{
    ViewBag.PartSecName = partSec.Name
    ViewBag.PartSecDesc = partSec.Desc
    var partProperties = db.PartProperties.Where(p => p.pSecID = partSec.ID);
    foreach(var partProp in partProperties)
    {
        ViewBag.PartPropName = partProp.Name
        ViewBag.PartPropDesc = partProp.Desc
    }
}
これで、上記のようなものが出力されるはずです。もちろん、このコードは機能しませんが、それが一般的な考え方です。だからこそ、私は助けを求めます。ありがとうございました。