本文介绍了如何创建多个表的列表并在单个视图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包装器类,其中包含两个表的对象以及数据库上下文
I have a wrapper class which contains the object of two tables and there DB context
public class StudentInfo
{
public StudentPersonalInfo PersonalInfo { get; set; }
public EducationQualification EducationalQualification { get; set; }
}
public class StudentDbContext:DbContext
{
public DbSet<StudentPersonalInfo> StudentPersonalInfos { get; set; }
public DbSet<EducationQualification> EducationQualifications { get; set; }
}
现在,在Controller中,我创建了StudentInfo类的列表并传递该类对象,并将其添加到列表中,如下所示,
Now in Controller I have create the List of StudentInfo class and pass that class objectand add them in list Like this,
// GET: /StudInfo/
public ActionResult Index1()
{
List<StudentInfo>sti = new List<StudentInfo>();
StudentInfo temp = new StudentInfo();
temp.PersonalInfo = new StudentPersonalInfo();
temp.EducationalQualification = new EducationQualification();
sti.Add(temp);
}
现在,我想在上下文中添加它,但不知道如何操作,所以请告诉我如何执行此操作,然后尝试在视图中显示列表.
请帮助
Now I wanted to add it in context and don’t know how to doo it, so please tell me how to do this and hoe to display the list in view.
Please help
推荐答案
这篇关于如何创建多个表的列表并在单个视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!