I'm trying to select the four most orderd products by query OrderLine by this statement:
var llist = (from line inOrderLine.All() group line by line.Sku into l selectnew{ Sku = l.Key, nbrLines = l.Sum(y => y.Quantity) } ).OrderBy(x => x.nbrLines).Take(4);
Looks like NHibernate is not too happy about the Take piece of your code.
We're upgrading NHibernate as quickly as new releases come out and I do see a new version out so I'll take that for a spin and see it that might fix the issue.
In the meantime you can either do some of the query with NH and the rest using LINQ to objects (.NET will switch to the latter when you do a ToList() and the subsequent query will be handled by LINQ to objects).
NHibernate supports a number of query mechanisms. Among them are HQL, which will let you do what you want.
Problem with Linq
Hi,
I'm trying to select the four most orderd products by query OrderLine by this statement:
var llist = (from line in OrderLine.All()
group line by line.Sku into l select new{
Sku = l.Key,
nbrLines = l.Sum(y => y.Quantity)
}
).OrderBy(x => x.nbrLines).Take(4);
But i get an exception
[NotImplementedException: The method or operation is not implemented.]
NHibernate.Linq.GroupBy.AggregatingGroupByRewriter.FlattenSubQuery(SubQueryExpression subQueryExpression, FromClauseBase fromClause, QueryModel queryModel) +436
NHibernate.Linq.GroupBy.AggregatingGroupByRewriter.ReWrite(QueryModel queryModel) +119
NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root) +62
NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory) +99
NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) +20
NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) +198
NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) +257
NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) +240
NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery) +42
NHibernate.Linq.NhQueryProvider.Execute(Expression expression) +47
Remotion.Data.Linq.QueryableBase`1.GetEnumerator() +56
CustomLogin.UserControls.FirstPageProducts.Page_Load(Object sender, EventArgs e) in C:\Projects\...\CustomLogin\UserControls\FirstPageProducts.ascx.cs:30
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Thanx!
I cant edit the post.
I's when I try to loop the result with an for each loop i get the Exception
Hi Niklas,
Looks like NHibernate is not too happy about the Take piece of your code.
We're upgrading NHibernate as quickly as new releases come out and I do see a new version out so I'll take that for a spin and see it that might fix the issue.
In the meantime you can either do some of the query with NH and the rest using LINQ to objects (.NET will switch to the latter when you do a ToList() and the subsequent query will be handled by LINQ to objects).
NHibernate supports a number of query mechanisms. Among them are HQL, which will let you do what you want.
is working on a reply...