Feb 13, 2019 06:10 PM|PatriceSc|LINK
You could use AsQueryable again as you have done previously :
.OrderBy(o => o.YearDocument).AsQueryable(); // rather than ToList();
Edit: ah and you are using an anonymous type which doesn't match your function return type which is IQueryable<EmpenhoDTO>. See my earlier sample :
- I'm using a Empenho class that would expose all data available from the database
- I'm selecting columns to create explictely a new EmphoDTO object that contains the properties I want to expose (see Edit2 as well)
I gave a closer look at NHibernate and though this is not for now a huge concern, note that you are retrieving data and then only select which columns you are interested in. If using your previous code with the Where clause you would likely retrieve ALL
rows and then only on the web server side you would filter them.
IMO you should have a look at
https://nhibernate.info/doc/nhibernate-reference/querylinq.html that shows how to use "Linq to NHibernate" to select columns or rows and have this processed on the database server rather than on the client side.
Edit2 : and so this is likely NOT how I would have approached this. If "extracted data" are never needed in queries my first thought would have been liiekly to add ready only properties that are just exposing parts of this CodRanking source string.
My other option would have been to create computed columns (if your db have support for that) so that even on the db side I could have this kind of data handy without having to extract data explicitely again and again.
Finally from a db design point of view, I would have created actual columns and would have exposed a single property or computed column that gathers all those pieces for convenience. For now you have to that because you are basically using a single column
to store multiple values.