实体框架“TPH”和“一对多”问题

时间:2013-05-02 09:55:44

标签: asp.net-mvc entity-framework inheritance code-first tph

所有问题都是:如何加载儿童的列表值,因为我的是空的。

我是EF初学者,我有一个问题:

我首先使用EF代码,我有4个关系“继承”和“一对多”的类,就像“Google Doc”的应用程序一样,我可以提出问题并展示它们,这里是类:

我使用TPH,而SurveyItem是拥有 descriminator

列的父类
public class SurveyItem  //SurveyItem Just like one question, and it's the base class
{
    public int SurveyItemId { get; set; }
    public int Number { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public bool IsRequired { get; set; }

    public int SurveyItemGroupId { get; set; }
    public virtual SurveyItemGroup SurveyItemGroup { get; set; }
}

public class MultiValueList:SurveyItem // this class in relationship inheritance and one to many
{
    public List<Option> Options { get; set; }
}

public class Option  //one MultiValueList has many Option
{
    public int OptionId { get; set; }
    public string Name { get; set; }
    public int Position { get; set; }
    public bool IsRight { get; set; }

    public int SurveyItemId { get; set; }
    public virtual MultiValueList MultiValueList { get; set; }

}

public class RadioButtonList:MultiValueList // the lowest class
{
}

然后我只想通过SurveyItemController.cs显示所有数据

        var surveyItems = (from list in db.SurveyItems.Include(s => s.SurveyItemGroup)
                           where list.SurveyItemGroupId == ThisSurveyGroupId
                           select list).ToList();

        return View(surveyItems.ToList());

在我的surveyItems.ToList()中,我无法获得选项记录,它们都是null,我如何获得选项?我想在我的surveyItems.cshtml页面中使用它们。

谢谢你们的任何帮助

0 个答案:

没有答案