EntityFramework Schema specified is not valid. Errors:

c# entity-framework

Question

Order Model

public partial class Orden
    {
        public Orden()
        {
            this.Orden_Bitacora = new HashSet<Orden_Bitacora>();
        }    
        //Attributes list    
        public virtual ICollection<Orden_Bitacora> Orden_Bitacora { get; set; }
    }

Orden_Bitacora Model

public partial class Orden_Bitacora
    {
        public int IdBitacora { get; set; }
        public int IdOrden { get; set; }

        public virtual Orden Orden { get; set; }
    }

But when I try to create a Order always display me the message:

Schema specified is not valid. Errors:

The relationship 'OrdenexTModel.FK_Orden_Bitacora_Orden' was not loaded because the type 'OrdenexTModel.Orden' is not available.

Its something wrong with the model declaration?

The relationship 'OrdenexTModel.FK_Orden_Bitacora_Orden' was not loaded because the type 'OrdenexTModel.Orden' is not available.

1
2
11/26/2014 5:26:47 PM

Accepted Answer

It cant find a Primary Key on Ordan and therefore the FK relationship will not work. Add the PK to Orden

public partial class Orden
{
    public int OrdenId { get; set; }
    public Orden()
    {
        this.Orden_Bitacora = new HashSet<Orden_Bitacora>();
    }    
    //Attributes list    
    public virtual ICollection<Orden_Bitacora> Orden_Bitacora { get; set; }
}

and you may need to add [Key] attribute to your Orden_Bitacora PK as it doesnt follow the Entity Framework naming convention

[Key]  
public int IdBitacora { get; set; }

or

public int Orden_BitacoraId

Hope that helps

1
11/28/2014 12:49:51 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow