-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NHibernate with AutoMapper and OData #2334
Comments
It seems unlikely to me that someone will investigate this with the information you currently supply. |
@fredericDelaporte I have created an example you asked: https://github.com/fairking/NhOdataTest
|
Thanks, I may have a look. But to be fair, this is not at the top of my priorities list. You may try investigate this a bit more by writing directly the equivalent Linq queries and check how they behave. Maybe you are just running into queries unsupported by Linq-to-nh. |
Thanks for your reply @fredericDelaporte :
I don't know what is the NH priority, but it must be top 1 priority if NH wants to stay on top today. |
This will be fixed by #2079. The query generated when using the mentioned PR: select
weatherfor0_.date as col_0_0_,
weatherfor0_.id as col_1_0_,
weatherfor0_.summary as col_2_0_,
weatherfor0_.temperature_c as col_3_0_,
@p0 + cast(cast(weatherfor0_.temperature_c as DOUBLE) / @p1 as INT) as col_4_0_,
weatherfor0_.id as col_5_0_
from
weather_forecast weatherfor0_ and this is how the expression from OData looks like:
|
@maca88 Thanks a lot mate. Any chance to get |
For group by the following expression is created by Automapper + OData: value(NHibernate.Linq.NhQueryable`1[NhOdataTest.Entities.WeatherForecast])
.Select(dtoWeatherForecast => new WeatherForecastVm()
{
Date = dtoWeatherForecast.Date,
Id = dtoWeatherForecast.Id,
Summary = dtoWeatherForecast.Summary,
TemperatureC = dtoWeatherForecast.TemperatureC,
TemperatureF = (32 + Convert((Convert(dtoWeatherForecast.TemperatureC, Double) / 0,5556), Int32))})
.Select($it => new FlatteningWrapper`1()
{
Source = $it,
GroupByContainer = new LastInChain() {Name = "Property0", Value = Convert($it.TemperatureC, Object)}
})
.GroupBy($it => new GroupByWrapper() {GroupByContainer = new LastInChain() {Name = "summary", Value = $it.Source.Summary}})
.Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, Container = new LastInChain()
{
Name = "total",
Value = Convert(Convert($it, IEnumerable`1).Average($it => Convert($it.GroupByContainer.Value, Int32)), Object)
}}) NHibernate would need to be able to rewrite it to: value(NHibernate.Linq.NhQueryable`1[NhOdataTest.Entities.WeatherForecast])
.GroupBy($it => new {GroupByContainer = $it.Summary})
.Select($it => new AggregationWrapper() {GroupByContainer = $it.Key.GroupByContainer, Container = new LastInChain() {
Name = "total",
Value = Convert(Convert($it, IEnumerable`1).Average($it => Convert($it.TemperatureC, Int32)), Object)
}}) which could be then translated to sql.
Not really, NHibernate is currently not smart enough to translate such qureries.
Most likely yes, I will give it a try in the near future. |
Thanks @maca88 I will include nh dev branch in my project temporary and give it a go with testing. My people are chasing me with reports working on |
I will definitely do testing of your branch. I'm really very thankful for your hard work. 👍 |
Tested and it's working like a charm 🥇 : OK You have to make sure you are using
Hope both of those fixed are included to the next release. |
NH v. 5.2.7
Not sure if it's a bug or not but I got an error trying to run Odata with projected AutoMapper Dto:
The url: http://localhost:8050/odata/Tickets?$select=id,name gives the following error:
The text was updated successfully, but these errors were encountered: