I'm having an error when I edit my profile, my Physical Model is as PartialView
, the following error occurs:
Attaching an entity of type 'Projeto.Models.Fisica' failed because another entity of the same type already has the same primary key value
MODEL REGISTRATION
public class Cadastro
{
public Pessoa Pessoa { get; set; }
public Fisica Fisica { get; set; }
}
PHYSICAL MODEL
public class Fisica : Pessoa
{
public string RG { get; set; }
}
MODEL PESSOA
public partial class Pessoa
{
[Key]
public int IdPessoa { get; set; }
public string Nome { get; set; }
}
VIEW EDIT
@model CodeFirst.Models.Cadastro
<div>
@Html.EditorFor(model => Model.Fisica)
</div>
PARTIAL VIEW PHYSICS
@model CodeFirst.Models.Fisica
<div class="col-xs-12 col-md-1-5 marginCimaBaixo">
@Html.LabelFor(model => model.RG)
@Html.EditorFor(model => model.RG)
@Html.ValidationMessageFor(model => model.RG)
</div>
CONTROLLER EDIT POST
public ActionResult Edit(Cadastro cadastro)
{
db.Entry(cadastro.Fisica).State = EntityState.Modified;
}
Thank you.