我在兩個表中插入是成功的,但我在索引操作中出現錯誤以顯示數據。無法查看索引在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