2
I am doubtful how to map a View created in Oracle Bank 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 perform the query of a column with alias.
select distinct("ID Navio") from vw_programacao;
In my application I am performing the consultation as follows:
var idNavios = Context.VWProgramacao.Select(e => e.IdNavio).Distinct();
But generates the following error:
{"ORA-00904: "Extent1 ". " ID_TRANSPORTE ": invalid identifier"}
I believe it is because of my mapping that I am wrong or maybe it is because of the alias of my view.
Any idea what it might be? Where I’m going wrong?
If you’re exposing the view with these aliases, you don’t have the ID_TRANSPORTE column, but ID Ship (Be very careful with these spaces, I wouldn’t recommend doing that). And replace to the correct value in all these properties.
– Renato Afonso
@Renatoafonso This view was created by another sector where I work, in this case in my application the name of my column is ... Hascolumnname("SHIP ID"); ?
– Samuel Renan Gonçalves Vaz
Yes. In these lines of code, you are associating your object’s property with the table column /view. In this case, your view has as column names those alias.
– Renato Afonso
@Renatoafonso I understood, I will change and do the test again.
– Samuel Renan Gonçalves Vaz
Do not map view with EF but tables.. you can make a select that returns everything you need with them.
– Marco Souza
@Renatoafonso I withdrew my answer to prioritize yours, if you are interested to answer a solution based on what I said, I will accept, because it worked as you said.
– Samuel Renan Gonçalves Vaz
@samuelrvg, I have already put as an answer. Thank you
– Renato Afonso