Speak Personal All right !? I have a problem that I would like to be helped.
Well I have a simple application with 4 related tables
I'musingtheentityframework6,myproblemisintheUSERSclass,becauseinrealityitisaVIEW,fromanotherdatabase,researchingthisIsawthatIcancreateanothercontext(readonly)Move View - Entity Framework to see this view, but my problem is that in other classes I need to have the relationship with the table How can I do this? When I include it in my main context the system tries to create the users table but it gives an error because the view already exists in the database.
Below is a snippet of my code:
public class BancoContexto: DbContext
{
public BancoContexto(): base("conexao")
{
this.Configuration.LazyLoadingEnabled = true;
}
public DbSet<LinhaProducao> LinhaProducao { get; set; }
public DbSet<AreaResponsavel> AreaResponsavel { get; set; }
public DbSet<Cartao> Cartao { get; set; }
public virtual DbSet<USUARIOS> USUARIOS { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<AreaResponsavel>().ToTable("AreaResponsavel");
modelBuilder.Entity<LinhaProducao>().ToTable("LinhaProducao");
modelBuilder.Entity<Cartao>().ToTable("Cartao");
//aqui é o meu problema
modelBuilder.Entity<USUARIOS>().ToTable("USUARIOS");
#endregion
base.OnModelCreating(modelBuilder);
}
}
public class AreaResponsavel
{
[Key]
public int AreaResponsavelID { get; set; }
public string NomeArea { get; set; }
public int UsuarioID { get; set; }
public virtual USUARIOS Responsavel { get; set; }
}
public class Cartao
{
public int CartaoID { get; set; }
public int NroCartao { get; set; }
public int OrdemProducao { get; set; }
public string Modelo { get; set; }
public string CodigoPeca { get; set; }
public string DescricaoProblema { get; set; }
public DateTime Data { get; set; }
public DateTime DataHoraInicio { get; set; }
public DateTime DataHoraFim { get; set; }
public int UsuarioID { get; set; }
public USUARIOS Colaborador { get; set; }
public int LinhaProducaoID { get; set; }
public LinhaProducao Linha { get; set; }
public int MaquinasAfetadas { get; set; }
public int AreaResponsavelID { get; set; }
public AreaResponsavel Area { get; set; }
public int LiderID { get; set; }
public USUARIOS Lider { get; set; }
public bool Gemba { get; set; }
}
public class LinhaProducao
{
public int LinhaProducaoID { get; set; }
public string NomeLinha { get; set; }
public int UsuarioID { get; set; }
public USUARIOS Responsavel { get; set; }
}
See that in the classes above I have a relationship with the User class !!!
Thanks in advance for your help!