模型调查CRUD是问题:
public class Survey
{
public int SurveyID { get; set; }
public string Question1 { get; set; }
public string Question2 { get; set; }
public string Question3 { get; set; }
public string Question4 { get; set; }
public string Question5 { get; set; }
}
此模型IntroResponse应具有应设置为Survey中设置的值的属性。 (IntroResponse是只读的,而不是创建或编辑问题属性):
public class IntroResponse : IValidatableObject
{
public int IntroResponseID { get; set; }
public int SurveyID { get; set; }
[ForeignKey("SurveyID")]
public virtual Survey Survey { get; set; }
public string Question1 { get; set; }
public string Question2 { get; set; }
public string Question3 { get; set; }
public string Question4 { get; set; }
public string Question5 { get; set; }
public IntroResponse()
{
//Code here?
}
正如您所看到的,这两个模型的实际情况是: SurveyID 1 -----> * IntroResponse
但我希望从Survey模型继承更多属性。如果不添加控制器代码,这可能吗?
我应该通过Entity Framework检索此信息还是只从数据库中获取值? 我找不到任何关于这个具体问题的早期主题。我真的好看。
请告诉我实现这一目标的最佳做法。
更新: 我想要的是当我通过下拉列表选择SurveyID时自动检索和显示的问题。这需要客户端代码,对吧?那么我应该让JavaScript代码进行数据库调用以获取问题吗?我不想以这种方式混合JavaScript和C#/ Razor代码。这就是为什么我要求一些指针!