views:

34

answers:

1

I heard about the new entity framework for .net, and decided to modify my code to use this framework, but when I try to add and delete records from the table, an Exception is thrown. I am NEW to this framework, so I can't figure out how to fix this or what is causing the exception. Here is my Code(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;
}

and here is my 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

Please keep in mind that I am new to this framework, and thanks for the help

+1  A: 

After rebuilding my project, the exception that had been thrown disappeared. I think something in the entity model got messed up, and this caused an exception, but after rebuilding my project, it 'fixed' itself.

geoff