0
I don’t know exactly what it’s called when it maps the return in the method like this, but I’ll try to explain, I have the following class for example:
public class Venda(){
public decimal Valor {get;set;}
public decimal Desconto {get;set;}
public decimal ValorLiquido => Valor - Descontos;
}
I use Entityframework and this class would be a model of the Database, I need to make a sales report and in this report I use the Property Value Net and the problem this here I do the following query:
var vendas = ctx.Vendas;
This returns me a Iqueryable so far ok, but if I try to use the property Valor liquido returns me the following message:
The specified type Member 'Valorliquido' is not supported in LINQ to Entities. Only initializers, Entity Members, and Entity navigation properties are supported.
If I give ToList()
it works and I can access the property, only it’s a report with more than 50,000 items, and in the real class, there are about 10 Getteronly Property for more, so it’s impossible to use ToList()
,
The question is:
Would have some way to access this property without giving Tolist() in the case in a Iqueryable list?
Why not use a View that loads your already calculated data, so much lower output (computes on the server), instead of loading 50K of records...and when it reaches 10 million? What you do?
– Ernesto Casanova
Would it be possible to parameterize this view by the application? In the case of this report the User can choose the filters, as date, form of payment and etc
– Edenilson Bila
Views are like a normal query to a table, but it allows you to map your output (only return what you want to see/access), make joins with other tables, calculations, aggregate data etc, doc microsoft https://docs.microsoft.com/en-us/sql/statements/create-view-Transact-sql?view=sql-server-2017. Its use in SQL is how to select a table to type SELECT * FROM [View_name] WHERE User LIKE '%An%', its use in EF, you have a post here https://stackoverflow.com/questions/7461265/how-use-views-in-code-first -Entity-framework.
– Ernesto Casanova
a view loads all the data before making the filters, will give you a headache, if you want to decrease the result set use a Where in your Linq ex: . Where(x=>x. liquid value=10). Tolist()
– Lucas Miranda
@Edenilsonbila from a read on this: https://answall.com/questions/17284/qual-a-diferen%C3%A7a-entre-ienumerable-iqueryable-e-list Iqueryable is a query tree, the data has not been "materialized" yet. so it is not possible to access the property Valorliquido
– Barbetta