View Mapping with Entity Framework

2

I'm wondering how to map a View created in Oracle Database 11G with Fluent-API.

Here is an excerpt from the view with alias:

tran.id_transporte AS "ID Navio",
tran.ds_nome_transporte AS "Navio",
pemb.id_porto AS "ID Porto Embarque",
pemb.ds_porto AS "Porto Embarque",
temb.id_terminal AS "ID Terminal",

In the mapping I did as follows:

        public VWProgramacaoEmbarque_Mapping()
    {
        this.HasKey(t => t.IdTerminal);
        this.ToTable("VW_PROGRAMACAO");

        this.Property(t => t.IdNavio).HasColumnName("ID_TRANSPORTE");
        this.Property(t => t.Navio).HasColumnName("DS_NOME_TRANSPORTE");
        this.Property(t => t.IdPortoEmbarque).HasColumnName("ID_PORTO");
        this.Property(t => t.PortoEmbarque).HasColumnName("DS_PORTO");
        this.Property(t => t.IdTerminal).HasColumnName("ID_TERMINAL");
    }

In Oracle I can query an aliased column.

select distinct("ID Navio") from vw_programacao;

In my application I'm performing the query as follows:

var idNavios = Context.VWProgramacao.Select(e => e.IdNavio).Distinct();

But it generates the following error:

  

{"ORA-00904: \" Extent1 \ ". \" TRAY_ID ": Invalid identifier"}

I think it's because of my mapping that is wrong or maybe it's because of the alias of my view.

Any idea what it might be? Where am I going wrong?

    
asked by anonymous 08.02.2018 / 17:29

2 answers

2

If you are exposing the view with these aliases, you do not have the ID_TRANSPORT column, but rather the Ship ID (Be very careful with these spaces, I do not recommend doing anything). And replace for the correct value in all these properties.

    
12.02.2018 / 08:48
1

This error occurs because you VIEW does not have the ID_TRANSPORTE column, perhaps at the time you created it you have placed:

See that you've placed this COLUMN as "Ship ID"

  

tran.id_transporte AS "Ship ID"

At the time of mapping to the Entity, you would need to name the "ALIAS" instead of the COLUMN itself, or if you remove the aliases, you can by the name of the COLUMNS.

For example, your mapping should look like this:

YOUR VIEW

tran.id_transporte AS "ID Navio",
tran.ds_nome_transporte AS "Navio",
pemb.id_porto AS "ID Porto Embarque",
pemb.ds_porto AS "Porto Embarque",
temb.id_terminal AS "ID Terminal", 

YOUR MAPPING WOULD HAVE TO BE THIS

public VWProgramacaoEmbarque_Mapping()
{
    this.HasKey(t => t.IdTerminal);
    this.ToTable("VW_PROGRAMACAO");

    this.Property(t => t.IdNavio).HasColumnName("ID Navio");
    this.Property(t => t.Navio).HasColumnName("Navio");
    this.Property(t => t.IdPortoEmbarque).HasColumnName("ID Porto Embarque");
    this.Property(t => t.PortoEmbarque).HasColumnName("Porto Embarque");
    this.Property(t => t.IdTerminal).HasColumnName("ID Terminal");
}

You would need to use the "ALIAS" if you are going to map using the names of the SPEAKERS simply would not need it for the Nicknames.

    
09.02.2018 / 22:30