Benjamin RD
Benjamin RD

Reputation: 12034

EntityFramework Schema specified is not valid. Errors:

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.

Upvotes: 2

Views: 22388

Answers (2)

Sagar Pol
Sagar Pol

Reputation: 1

Go to EntityFramework .edmx file which will open an entity framework, Right click and select Update Model from Database, select okey it will get updated as changes might have done in database.

Upvotes: 0

SWilko
SWilko

Reputation: 3612

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

Upvotes: 2

Related Questions