Srs...
Preciso fazer um update via Entity Framework, mas estou recebendo a seguinte mensagem de erro.
"An object with a key that matches the key of the supplied object could not be found in the ObjectStateManager. Verify that the key values of the supplied object match the key values of the object to which changes must be applied."
Estou usando o código abaixo.
protected void Button_Salvar_Click(object sender, EventArgs e)
{
String pCpf = Request.QueryString["pCpf"];
String pAcao = Request.QueryString["pAcao"];
PortalEntities entidades = new PortalEntities();
var Dados = (from cur in entidades.tCurriculo where cur.cr_cpf.Equals(pCpf) select cur).First();
//Grava dados sobre o Curriculo em dbo.tCurriculo
try
{
using (PortalEntities db = new PortalEntities())
{
tCurriculo NovoCurriculo = new tCurriculo()
{
cr_nome = TextBox_Nome.Text,
cr_estadocivil = DropDownList_EstCiv.SelectedValue.ToString(),
cr_sexo = DropDownList_Sexo.SelectedValue.ToString(),
cr_telefone = TextBox_Tel1.Text,
cr_telefone2 = TextBox_Tel2.Text,
cr_celular = TextBox_Cel1.Text,
cr_celular2 = TextBox_Cel2.Text,
cr_email = TextBox_Email.Text,
cr_endereco = TextBox_End.Text,
cr_bairro = TextBox_Bai.Text,
cr_cidade = TextBox_Cid.Text,
cr_cep = TextBox_Cep.Text,
cr_uf = TextBox_Uf.Text,
cr_interesse = DropDownList_Area.SelectedValue,
cr_objetivo = TextBox_Obj.Text,
cr_experiencia1 = TextBox_Exp1.Text,
cr_experiencia2 = TextBox_Exp2.Text,
cr_experiencia3 = TextBox_Exp3.Text,
cr_empregado = DropDownList_Emp.SelectedValue
};
if (Request.QueryString["pAcao"] == "A")
{
db.tCurriculo.ApplyCurrentValues(NovoCurriculo);
}
//db.tCurriculo.AddObject(NovoCurriculo);
db.SaveChanges();
}
}
catch (Exception ex)
{
//Tratar erros
}
}
Se possivel gostaria de usar o mesmo webform para INSERT quanto para UPDATE do registro/entidade.
Onde estou errando ?
Grato pela oportunidade