-7
I have an error when I edit my registration, my Physical Model is like 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 REGISTER
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 PERSON
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 PHYSICAL VIEW
@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.
Now you’ve made the right inheritance. I’ll answer.
– Leonel Sanches da Silva
Dear Lord, almost a thousand points and you still don’t know what "thank you" is done with +1? That’s noise my dear, Furlan, is there in the 1st guide that we should read when you start using this site: [tour] --->
não tem bla bla bla
. Thank you for understanding!– brasofilo