我听说了.net 的新实体框架,并决定修改我的代码以使用这个框架,但是当我尝试从表中添加和删除记录时,抛出了一个异常。我是这个框架的新手,所以我不知道如何解决这个问题或导致异常的原因。这是我的代码(c#):
try
{
string key = Request.QueryString["account"].ToString();
FormDataEntities en = new FormDataEntities();
DbUser usr = new DbUser();
usr.uid = (from b in en.DbUnactivatedUserSet where b.active == key select b.uid).FirstOrDefault();
usr.pwd = (from b in en.DbUnactivatedUserSet where b.active == key select b.pwd).FirstOrDefault();
usr.firstname = (from b in en.DbUnactivatedUserSet where b.active == key select b.firstname).FirstOrDefault();
usr.lastname = (from b in en.DbUnactivatedUserSet where b.active == key select b.lastname).FirstOrDefault();
en.AddToDbUserSet(usr);
DbUnactivatedUser un = (from b in en.DbUnactivatedUserSet where b.active == key select b).FirstOrDefault();
en.DeleteObject(un);
en.SaveChanges();
Label1.Text = "message";
}
catch (Exception ex)
{
Label1.Text = ex.StackTrace;
}
这是我的 StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
at System.Data.Objects.ObjectContext.SaveChanges()
at ASP.pages_activate_aspx.Page_Load(Object sender, EventArgs e)
in c:\inetpub\My Web Sites\mysite\Pages\Activate.aspx:line 26
请记住,我是这个框架的新手,感谢您的帮助