C# 我正在尝试创建web应用程序,但发现EntityCommandExecutionException
我试图创建一个web应用程序,但发现EntityCommandExecutionException,这是我的控制器类C# 我正在尝试创建web应用程序,但发现EntityCommandExecutionException,c#,visual-studio-2010,asp.net-mvc-3,C#,Visual Studio 2010,Asp.net Mvc 3,我试图创建一个web应用程序,但发现EntityCommandExecutionException,这是我的控制器类 namespace DemoMVC.Controllers { public class ContactController : Controller { ContactContext db = new ContactContext(); public ActionResult Index() {
namespace DemoMVC.Controllers
{
public class ContactController : Controller
{
ContactContext db = new ContactContext();
public ActionResult Index()
{
var contact = db.Contacts.ToList();
return View(contact);
}
public ActionResult Details(int id)
{
return View();
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Contact person)
{
try
{
// TODO: Add insert logic here
db.Contacts.Add(person);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Contact/Edit/5
public ActionResult Edit(int id)
{
return View();
}
//
// POST: /Contact/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Contact/Delete/5
public ActionResult Delete(int id)
{
return View();
}
//
// POST: /Contact/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
这是我的连接字符串
<add name="ContactContext" connectionString="Data Source=RMSIPDB;Initial Catalog=CoroporateApps;User ID=CorApps;Password=CorApps_123"
providerName="System.Data.SqlClient" />
And this is my View Page
@model IEnumerable<DemoMVC.Models.Contact>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Name
</th>
<th>
Address
</th>
<th>
Mobile
</th>
<th>
DataDate
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.Mobile)
</td>
<td>
@Html.DisplayFor(modelItem => item.DataDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
这是我的查看页面
@模型IEnumerable
@{
ViewBag.Title=“Index”;
}
指数
@ActionLink(“新建”、“创建”)
名称
地址
可移动的
数据日期
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.Name)
@DisplayFor(modelItem=>item.Address)
@DisplayFor(modelItem=>item.Mobile)
@DisplayFor(modelItem=>item.DataDate)
@ActionLink(“编辑”,“编辑”,新的{id=item.id})|
@ActionLink(“详细信息”,“详细信息”,新的{id=item.id})|
@ActionLink(“删除”,“删除”,新的{id=item.id})
}
当我执行代码时,我得到EntityCommandExecutionException,有人能帮我吗 什么是stacktrace?您能给出原始异常吗?@RalphJansen StackTrace:at System.Data.EntityClient.EntityCommandDefinition.ExecuteStorommands(EntityCommand EntityCommand,CommandBehavior行为)at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext上下文,ObjectParameterCollection参数值)在System.Data.Objects.ObjectQuery的System.Data.Objects.ObjectQuery
1.GetResults(Nullable
1 forMergeOption)中,在System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()中,可以设置断点吗?星图对吗?@RalphJansen是的。。。但是在public ActionResult Index()上的执行正在停止{var contact=db.Contacts.ToList();return View(contact);}您能检查innerexception吗?我认为真正的问题在那里。