我在两个表中插入是成功的,但我在索引操作中出现错误以显示数据。无法查看索引在MVC中显示数据的操作
模型和视图模型。
视图模型
public class VMUsers
{
public int Id { get; set; }
public string FullName { get; set; }
public string LastName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
}
模型
[Table("tblUsers")]
public class Users
{
[Key]
public int Id { get; set; }
public string FullName { get; set; }
public string LastName { get; set; }
}
[Table("tblUserDetails")]
public class UserDetails
{
[Key]
public int Id { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public int UserID { get; set; }
}
DBSet
public System.Data.Entity.DbSet<MVCLearning.Models.VMUsers> Combination { get; set; }
索引操作
public ActionResult Index()
{
return View(db.Combination.ToList());
}
入门例外
类型“System.Data.Entity.Core.EntityCommandExecutionException”的一个例外发生在EntityFramework.SqlServer.dll但在用户代码中没有处理
其他信息:在执行时发生错误命令定义。详情请参阅内部例外。
不知道这是什么内在的excepton。
它打破了,所以看到错误的调试部分也打破了它不去视图调试。
'VMUsers'是一个视图模型,而不是数据模型。它不应该与EF有任何关系。 –
另外,你确定你的实体模型定义是正确的吗?表格之间是否有足够的外键关系? – Shyju
好像现在正在考虑在两张表中添加数据,所以保持简单,没有保存PK和FK,但实时PK和FK将在那里。 – Dave