EF using an inexisting column

0

When I run this code:

IEnumerable<Processo> filtrados = db.Processoes
                .Include(s => s.ProcessoClientes)
                .ToList();

I got this Exception:

[SqlException (0x80131904): Invalid column 'Cliente_ID']

The class ProcessoClientes doesnt have a column named Cliente_ID.

public class ProcessoCliente 
    {
        [Key]
        public int ID { get; set; }

        [Required]
        public int PessoaID { get; set; }
        public virtual Pessoa Pessoa { get; set; }

        [Required]
        public int CondicaoID { get; set; }
        public virtual Condicao Condicao { get; set; }

        [Required]
        public int ProcessoID { get; set; }
        public virtual Processo Processo { get; set; }
    }

And the database table ProcessoClientes doesnt have too.

enter image description here

Then I resolved reset my migrations to get an map of the table in database as EF are seeing it. And I received this:

CreateTable(
                "dbo.ProcessoClientes",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        PessoaID = c.Int(nullable: false),
                        CondicaoID = c.Int(nullable: false),
                        ProcessoID = c.Int(nullable: false),
                        Cliente_ID = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Condicaos", t => t.CondicaoID, cascadeDelete: true)
                .ForeignKey("dbo.Clientes", t => t.Cliente_ID)
                .ForeignKey("dbo.Pessoas", t => t.PessoaID, cascadeDelete: true)
                .ForeignKey("dbo.Processoes", t => t.ProcessoID, cascadeDelete: true)
                .Index(t => t.PessoaID)
                .Index(t => t.CondicaoID)
                .Index(t => t.ProcessoID)
                .Index(t => t.Cliente_ID);

If this column does not exist in the database table, where is EF bringing it when mounts the migration?

asp.net-mvc
entity-framework
asked on Stack Overflow Apr 25, 2018 by Neumann

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0