Good morning!
I comment, I'm having the need to add a Model in EF, but with the peculiarity that you use a Query SQL as a source of information instead of a table.
I tried to do it by the normal ways in the following way
[Table("[dbo].[ViewCuboVenta]")]
public class CuboVentas
{
[Key]
[Column("[ClienteRazon]",Order = 2)]
public string Cliente { get; set; }
[Key]
[Column("[NumeroCotizacion]",Order = 0)]
public string Nota_de_Venta { get; set; }
[Key]
[Column("[ArtiCodiCompuesto]",Order = 1)]
public string Cod_Fabricacion { get; set; }
}
The issue is that it throws an exception saying that none of my columns exist.
SqlException: Invalid column name '[CallNumber]'. Invalid column name '[NumeroCotizacion]'. Invalid column name '[ArtiCodiCompuesto]'. Invalid column name '[ClientRazon]'.
The issue of consulting a query is an obligation, since I do not have access to the complete database, but only some Query, and I would need this to use it as a Repository, (have the client's name, quote and article purchased)
I clarify that being a Query does not really have primary Keys in the database, but if I do not assemble it as a composite key I will have repetition of primary keys in the model
Is there a way to do it with a DBContext? or directly the solution is to perform the query in a conventional way?
Thank you very much for your time!