I'm working on my final project with Visual Studio 2015 with C#. I'm doing an app that works as simulator of an Android Game, and I have some characters (models.Personaje). And those characters have abilities (BB) and when I want to do the migrations it threws:
Schema specified is not valid. Errors: The relationship 'Projecte_Final.Models.Personaje_BB' was not loaded because the type 'Projecte_Final.Models.BB' is not available.
I don't know what am I doing wrong, here are the models BB and Personaje.
BB Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Projecte_Final.Models
{
public class BB
{
public int ID { get; set; }
//Habilidades de los personajes
public String Nombre { get; set; }
public String BBDesc { get; set; }
//Rama del BB (Heal, Support o Atk)
public int RamaBBID { get; set; }
public virtual RamaBB RamaBB { get; set; }
//Tipo del BB (BB, SBB, UBB)
public int TipoBBID { get; set; }
public virtual TipoBB TipoBB { get; set; }
//Grupalidad del BB
public int GrupalBBID { get; set; }
public virtual GrupalBB GrupalBB { get; set; }
public int NhitsBB { get; set; }
public int DCBB { get; set; }
public int CosteBB { get; set; }
public int MultiplicadorBB { get; set; }
public int EfectoBBID { get; set; }
public virtual Efectos EfectoBB { get; set; }
public virtual ICollection<Personaje> Personajes { get; set; }
}
}
Personaje Model
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Projecte_Final.Models
{
public class Personaje
{
//Personaje del juego.
//Datos generales
public int Numero { get; set; }
public String Nombre { get; set; }
public int NivelMax { get; set; }
public int Estrellas { get; set; }
public int Coste { get; set; }
public virtual ICollection<Stats> Stats { get; set; }
//Elemento
public int ElementoID { get; set; }
public virtual Elemento Elemento { get; set; }
//Genero
public int GeneroID { get; set; }
public virtual Genero Genero { get; set; }
//Datos combate
public int NHits { get; set; }
public int DC { get; set; }
//BB
public int? BBID { get; set; }
public virtual BB BB { get; set; }
//SBB
public int? SBBID { get; set; }
public virtual BB SBB { get; set; }
//UBB
public int? UBBID { get; set; }
public virtual BB UBB { get; set; }
//Datos IMPS
public int ImpHP { get; set; }
public int ImpAtk { get; set; }
public int ImpDef { get; set; }
public int ImpRec { get; set; }
//Descripciones extras
public int? LSID { get; set; }
public virtual LS LS { get; set; }
public int? ESID { get; set; }
public virtual ES ES { get; set; }
//Pre i post evoluciones
public int? PreEvoNum { get; set; }
public virtual Personaje PreEvo { get; set; }
public int? PostEvoNum { get; set; }
public virtual Personaje PostEvo { get; set; }
//Imágenes
[NotMapped]
public HttpPostedFileBase Imagen { get; set; }
[NotMapped]
public HttpPostedFileBase Icono { get; set; }
[NotMapped]
public HttpPostedFileBase Gif { get; set; }
[NotMapped]
public HttpPostedFileBase GifAtaque { get; set; }
//Propiedad de navegacion propia
public virtual ICollection<Personaje> Personajes { get; set; }
//Propiedad de navegacion a Unidad
public virtual ICollection<Unidad> Unidades { get; set; }
}
}
And here it is the code for the db context for models BB and Personaje:
//BB
modelBuilder.Entity<BB>().HasKey(x => x.ID);
modelBuilder.Entity<BB>().HasRequired(x => x.RamaBB).WithMany(x => x.BBRama).HasForeignKey(x => x.RamaBBID);
modelBuilder.Entity<BB>().HasRequired(x => x.TipoBB).WithMany(x => x.BBTipo).HasForeignKey(x =>x.TipoBBID);
modelBuilder.Entity<BB>().HasRequired(x => x.GrupalBB).WithMany(x => x.BBGrupal).HasForeignKey(x => x.GrupalBBID);
modelBuilder.Entity<BB>().HasRequired(x => x.EfectoBB).WithMany(x => x.BBEfectos).HasForeignKey(x => x.EfectoBBID);
//Personaje
modelBuilder.Entity<Personaje>().HasKey(x => x.Numero);
modelBuilder.Entity<Personaje>().HasRequired(x => x.Elemento).WithMany(x => x.Personajes).HasForeignKey(x => x.ElementoID);
modelBuilder.Entity<Personaje>().HasRequired(x => x.Genero).WithMany(x => x.Personajes).HasForeignKey(x => x.GeneroID);
modelBuilder.Entity<Personaje>().HasOptional(x => x.BB).WithMany(x => x.Personajes).HasForeignKey(x => x.BBID);
modelBuilder.Entity<Personaje>().HasOptional(x => x.SBB).WithMany(x => x.Personajes).HasForeignKey(x => x.SBBID);
modelBuilder.Entity<Personaje>().HasOptional(x => x.UBB).WithMany(x => x.Personajes).HasForeignKey(x => x.UBBID);
modelBuilder.Entity<Personaje>().HasOptional(x => x.ES).WithMany(x => x.Personajes).HasForeignKey(x => x.ESID);
modelBuilder.Entity<Personaje>().HasOptional(x => x.LS).WithMany(x => x.Personajes).HasForeignKey(x => x.LSID);
modelBuilder.Entity<Personaje>().HasOptional(x => x.PreEvo).WithMany(x => x.Personajes).HasForeignKey(x => x.PreEvoNum);
modelBuilder.Entity<Personaje>().HasOptional(x => x.PostEvo).WithMany(x => x.Personajes).HasForeignKey(x => x.PostEvoNum);
I hope that you can help me, thank you.