Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good afternoon, I'm having problems in the generation of records relating to the class Person and Individual.
The PessoFisica table has a relationship with the Person table would be 1: 1 relationship, it happens that the primary key of Table PessoaFisica is being inserted in place the primary key table Person. And the person of ForeingKey is not being filled with shows in the picture:

http://i.stack.imgur.com/bGBEc.png[^]

http://i.stack.imgur.com/WS1ZC.png[^]

http://i.stack.imgur.com/kn4oK.png[^]

C#
public ActionResult Index()
    {
        var rnd = new Random();

        // Pessoa
        var pessoa = new Pessoa()
        {
            DataCadastro = DateTime.Now,
            Ativo = true,
            NegarCredito = false
        };

     // PF de Pessoa
        var pessoaFisica = new PessoaFisica()
        {
            Nome = "Nome " + rnd.Next(1, 13),
            Cpf = "321456987" + rnd.Next(1, 13),
            Pessoa = pessoa
        };

        // Instancia do Contexto do EF
        var contexto = new ApplicationDbContext();

        //#### INICIO SETUP de PF, PJ e Endereços ####

    // Adicionando PF em Pessoa
        pessoa.PessoaFisica = pessoaFisica;

        // Adicionando Pessoa no Contexto
        contexto.Pessoa.Add(pessoa);

        // Salvando todas as inclusões
        contexto.SaveChanges();


It is normal to happen this Part class has the same ID the whole class?

What I have tried:

I've tried this way and does not work. It is right in a relationship one to one the key to the whole class appear as a primary key in the table of the case: PessoaFisicaId = PeopleID

http://imgur.com/vCGQSyv[^]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900