Continuation to the previous question, I tried to avoid the problem another way:
Just for the reminder:
My database schema is described below:
Form <-> Log
<--->>Seller1
<--->>Seller2
<--->>Seller3
I have a major entity (Form), one to
one relationship to another object
(Log) And one to many relationship to
the childs (Sellers).
I want to pull out all the Forms that
one of their Sellers meets certain
conditions.
I tried like this now:
[Test]
public void Can_Get_Forms_Where_CorporationNumber_Is_510778087_Metohd1()
{
var CorporationNumber = "513514950";
var list1 = sellerRepository
.Where(x => x.CorporationNumber == CorporationNumber)
.Select(x => x.Form)
.Fetch(x => x.Log)
.Take(10).ToList();
CollectionAssert.IsNotEmpty(list1);
}
But unfortunately I get NullReferenceException:
TestUsingDevelopmentDataBase.Moch.BillOfSale.Data.FormRepositoryTests.Can_Get_Forms_Where_CorporationNumber_Is_510778087_Metohd1:
System.NullReferenceException : Object
reference not set to an instance of an
object
EDIT: stacktrace:
at
NHibernate.Linq.Visitors.ResultOperatorProcessors.ProcessFetch.Process(FetchRequestBase
resultOperator, QueryModelVisitor
queryModelVisitor, IntermediateHqlTree
tree) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\ResultOperatorProcessors\ProcessFetch.cs:line
11 at
NHibernate.Linq.Visitors.ResultOperatorProcessors.ProcessFetchOne.Process(FetchOneRequest
resultOperator, QueryModelVisitor
queryModelVisitor, IntermediateHqlTree
tree) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\ResultOperatorProcessors\ProcessFetchOne.cs:line
9 at
NHibernate.Linq.Visitors.ResultOperatorProcessors.ResultOperatorProcessor1.Process(ResultOperatorBase
resultOperator, QueryModelVisitor
queryModel, IntermediateHqlTree tree)
in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\ResultOperatorProcessors\ResultOperatorProcessor.cs:line
17 at
NHibernate.Linq.Visitors.ResultOperatorProcessors.ResultOperatorMap.Process(ResultOperatorBase
resultOperator, QueryModelVisitor
queryModel, IntermediateHqlTree tree)
in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\ResultOperatorProcessors\ResultOperatorMap.cs:line
24 at
NHibernate.Linq.Visitors.QueryModelVisitor.VisitResultOperator(ResultOperatorBase
resultOperator, QueryModel queryModel,
Int32 index) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\QueryModelVisitor.cs:line
125 at
Remotion.Data.Linq.Clauses.ResultOperatorBase.Accept(IQueryModelVisitor
visitor, QueryModel queryModel, Int32
index) at
Remotion.Data.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection1
resultOperators, QueryModel
queryModel) at
Remotion.Data.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel
queryModel) at
NHibernate.Linq.Visitors.QueryModelVisitor.Visit()
in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\QueryModelVisitor.cs:line
96 at
NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel
queryModel, VisitorParameters
parameters, Boolean root) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\Visitors\QueryModelVisitor.cs:line
49 at
NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor
sessionFactory) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhLinqExpression.cs:line
67 at
NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String
queryIdentifier, IQueryExpression
queryExpression, String
collectionRole, Boolean shallow,
IDictionary2 filters,
ISessionFactoryImplementor factory) in
d:\CSharp\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line
27 at
NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String
expressionStr, IQueryExpression
queryExpression, String
collectionRole, Boolean shallow,
IDictionary2 enabledFilters,
ISessionFactoryImplementor factory) in
d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line
34 at
NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String
expressionStr, IQueryExpression
queryExpression, String
collectionRole, Boolean shallow,
IDictionary2 enabledFilters,
ISessionFactoryImplementor factory) in
d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line
23 at
NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String
expressionStr, IQueryExpression
queryExpression, Boolean shallow,
IDictionary2 enabledFilters,
ISessionFactoryImplementor factory) in
d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line
17 at
NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression
queryExpression, Boolean shallow,
IDictionary2 enabledFilters) in
d:\CSharp\NH\nhibernate\src\NHibernate\Engine\Query\QueryPlanCache.cs:line
88 at
NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression
queryExpression, Boolean shallow) in
d:\CSharp\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line
302 at
NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression
queryExpression) in
d:\CSharp\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line
258 at
NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression
expression, IQuery& query,
NhLinqExpression& nhQuery) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line
42 at
NHibernate.Linq.NhQueryProvider.Execute(Expression
expression) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line
25 at
NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression
expression) in
d:\CSharp\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line
102 at
Remotion.Data.Linq.QueryableBase1.GetEnumerator()
at
System.Collections.Generic.List1..ctor(IEnumerable1
collection) at
System.Linq.Enumerable.ToList[TSource](IEnumerable`1
source) at
TestUsingDevelopmentDataBase.Moch.BillOfSale.Data.FormRepositoryTests.Can_Get_Forms_Where_CorporationNumber_Is_510778087_Metohd1()
in
D:\Dev\NCommon\Moch.BillOfSale\Moch.BillOfSale.NHibenate.Tests\FormRepositoryTests.cs:line
207
The problem could be circumvented in a less well, as follows:
[Test]
public void Can_Get_Forms_Where_CorporationNumber_Is_510778087_Metohd2()
{
var CorporationNumber = "513514950";
var list2 = sellerRepository
.Where(x => x.CorporationNumber == CorporationNumber)
.Fetch(x => x.Form).ThenFetch(x => x.Log)
.Take(10).ToList().Select(x => x.Form);
CollectionAssert.IsNotEmpty(list2);
}
But of course we all prefer the elegant way and want to understand what lies behind the problem
I think Nhibernate doesn't like you fetching after a select. I ran into a null reference exception just like you did.
See my question here about it.
In Linq-to-Nhibernate, is it possible to use .Fetch() after a .Select()?
You might be able to .Select(x => x.Form) after your fetching in your second example before you .ToList() it, too.
I'm using Nhibernate 3.2 and this is still an issue. There should be a proper 'you can't fetch after a select' exception or something to spare us some pain.
Related
I'm using the Invantive Query Tool to update address data for suppliers in Exact Online on a large scale. I've written some VBA code that generates SQL code to put into the Invantive Query Tool. I've used this before and it worked fine, I've updated hundreds of Exact Online table values about 1 or 2 months ago. Now I wanted to use the same code to run a new update, however I get errors I didn't get before.
Let's start with the code that worked before:
use 1091919
UPDATE exactonlinerest..Accounts
SET AddressLine1='Nieuw Walden 56-64'
WHERE code like '% 500053'
AND AddressLine1 != 'Nieuw Walden 56-64'
AND division = 1091919
When I run this I get the error:
Unknown identifier: 'AddressLine1'."
and get the suggestion to use "AddressLine1_".
So I add the underscore and it does seem to remove the error in finding AddressLine1, however I get a new error that reads:
Unknown identifier: 'ID'.
and I have no idea where it comes from. These are the error details:
UPDATE exactonlinerest..Accounts SET AddressLine1_='Nieuw Walden 56-64' WHERE code like '% 500053' AND AddressLine1_ != 'Nieuw Walden 56-64' AND division = 1091919
Type: Invantive.Configuration.ValidationException
bij Invantive.Configuration.ValidationException..ctor(String errorCode,
String errorMessage, String kindRequest, String localStackTrace,
String nk, Exception innerException)
bij Invantive.Sql.ExpressionParser.<>c__DisplayClass4_0.CreateExpressionParser>b__1(String qualifiedColumnName)
bij Invantive.Data.ExtensionMethods.TryGetValue[TKey,TValue](Dictionary`2dictionary, TKey key, Func`2 customExceptionFunction)
bij Invantive.Sql.ExpressionParser.<>c__DisplayClass4_0.<CreateExpressionParser>b__0(String name)
bij Invantive.Sql.TransformToExpression.GetExpressionForField(String fieldName, Type& type)
bij Invantive.Sql.TransformToExpression.GetProjectionForField(String fieldName, Type& type)
bij Invantive.Sql.UpdateStatementTree.CompileInternal(ParameterList parameters, ExpressionParser expressionParser)
bij Invantive.Sql.QueryTree.Compile(ParameterList parameters,ExpressionParser expressionParser)
bij Invantive.Sql.QueryPlan.ForcePlan()
bij Invantive.Sql.QueryPlan.get_Fields()
bij Invantive.Data.ConnectionManager.ExecuteProviderPassthroughSqlAction(String actionSql, ParameterList parameters, String& handlingPath)
bij Invantive.Data.ConnectionManager.PassthroughSqlAction(String actionSql, ParameterList parameters)
bij Invantive.Data.ActionProceduresBase.PassthroughSqlAction(String actionSql, ParameterList parameters)
bij Invantive.Producer.Windows.Forms.QueryTool.ExecuteStatement(IProgressNotifier notifier, String statement, ParameterList bindVariables, Boolean showResultsInGrid, Boolean showStatistics, Boolean memorizeStatisticsInSqlHistory, Boolean allowPaging)
bij Invantive.Producer.Windows.Forms.QueryTool.FetchResultsFromSql()
bij Invantive.Producer.Windows.Forms.QueryTool.<>c__DisplayClass135_0.<FetchData>b__0()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
bij Invantive.Data.ExtensionMethods.TryGetValue[TKey,TValue](Dictionary`2 dictionary, TKey key, Func`2 customExceptionFunction) in File216:regel 1601
bij Invantive.Sql.ExpressionParser.<>c__DisplayClass4_0.<CreateExpressionParser>b__0(String name) in File118:regel 53
bij Invantive.Sql.TransformToExpression.GetExpressionForField(String fieldName, Type& type) in File115:regel 826
bij Invantive.Sql.TransformToExpression.GetProjectionForField(String fieldName, Type& type) in File115:regel 878
bij Invantive.Sql.UpdateStatementTree.CompileInternal(ParameterList parameters, ExpressionParser expressionParser) in File112:regel 132
bij Invantive.Sql.QueryTree.Compile(ParameterList parameters, ExpressionParser expressionParser) in File131:regel 91
bij Invantive.Sql.QueryPlan.ForcePlan() in File130:regel 86
bij Invantive.Sql.QueryPlan.get_Fields() in File130:regel 63
bij Invantive.Data.ConnectionManager.ExecuteProviderPassthroughSqlAction(String actionSql, ParameterList parameters, String& handlingPath) in File39:regel 3754
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bij Invantive.Data.ConnectionManager.ExecuteProviderPassthroughSqlAction(String actionSql, ParameterList parameters, String& handlingPath) in File39:regel 3789
bij Invantive.Data.ConnectionManager.PassthroughSqlAction(String actionSql, ParameterList parameters) in File39:regel 1928
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bij Invantive.Data.ConnectionManager.PassthroughSqlAction(String actionSql, ParameterList parameters) in File39:regel 1940
bij Invantive.Data.ActionProceduresBase.PassthroughSqlAction(String actionSql, ParameterList parameters) in File29:regel 212
bij Invantive.Producer.Windows.Forms.QueryTool.ExecuteStatement(IProgressNotifier notifier, String statement, ParameterList bindVariables, Boolean showResultsInGrid, Boolean showStatistics, Boolean memorizeStatisticsInSqlHistory, Boolean allowPaging) in File934:regel 2876
bij Invantive.Producer.Windows.Forms.QueryTool.FetchResultsFromSql() in File934:regel 2459
I'd appreciate it very much if this error can be fixed.
This ended up to be a bug in the evaluation in the SQL engine.
Please let me know if it still happens to you.
Using Orchard.Projections module, it's not possible to search in Unicode text. For example the result query is Select ... From ... Where ... Col Like '%term%' but we expected Select ... From ... Where ... Col Like N'%term%' (N included after Like). Looking it up in code we find public static BinaryExpression Like() in Orchard.ContentManagement.HqlRestrictions. By adding N and changing value = "'%" + FormatValue(value, false) + "%'"; into value = "N'%" + FormatValue(value, false) + "%'"; we get this error:
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException was caught
HResult=-2146232832
Message=Exception of type 'Antlr.Runtime.MismatchedTokenException' was thrown. near line 9, column 61
Source=NHibernate
StackTrace:
at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Hql\Ast\ANTLR\ErrorCounter.cs:line 73
at NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs:line 479
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 19
at NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 24
at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 16
at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\HQLStringQueryPlan.cs:line 14
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\Query\QueryPlanCache.cs:line 62
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line 310
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line 289
at Orchard.ContentManagement.DefaultHqlQuery.Slice(Int32 skip, Int32 count) in d:\Projects\...\src\Orchard\ContentManagement\DefaultHqlQuery.cs:line 188
at Orchard.Projections.Services.ProjectionManager.GetContentItems(Int32 queryId, Int32 skip, Int32 count)
at Orchard.Projections.Drivers.ProjectionPartDriver.<>c__DisplayClass2e.<Display>b__1e(Object shape)
at Orchard.ContentManagement.Drivers.ContentPartDriver`1.<>c__DisplayClass12.<ContentShape>b__11(BuildShapeContext ctx) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentPartDriver.cs:line 135
at Orchard.ContentManagement.Drivers.ContentPartDriver`1.<>c__DisplayClass15.<ContentShapeImplementation>b__14(BuildShapeContext ctx) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentPartDriver.cs:line 140
at Orchard.ContentManagement.Drivers.ContentShapeResult.ApplyImplementation(BuildShapeContext context, String displayType) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentShapeResult.cs:line 45
at Orchard.ContentManagement.Drivers.ContentShapeResult.Apply(BuildDisplayContext context) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\ContentShapeResult.cs:line 21
at Orchard.ContentManagement.Drivers.CombinedResult.Apply(BuildDisplayContext context) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\CombinedResult.cs:line 28
at Orchard.ContentManagement.Drivers.Coordinators.ContentPartDriverCoordinator.<>c__DisplayClassa.<BuildDisplay>b__9(IContentPartDriver driver) in d:\Projects\...\src\Orchard\ContentManagement\Drivers\Coordinators\ContentPartDriverCoordinator.cs:line 49
at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger) in d:\Projects\...\src\Orchard\InvokeExtensions.cs:line 17
InnerException:
line 9, column 61 indicates the position of 'N'.
Any idea?
How can we use this module to search in unicode text without changing database collation?
Orchard version is 1.8.1
Quick fix. I've changed collation setting directly of database
I've a problem with following Hql Query:
FROM PhysikalischesObjekt physikalischesObjekt LEFT OUTER JOIN FETCH physikalischesobjekt.AktuelleInstallation installation
As you see - i'm using aliases that named like the entity (just with lower letter at the first position).
If im execute this query to Nhibernate, i get a InvalidPathException:
NHibernate.Hql.Ast.ANTLR.InvalidPathException : Invalid path: 'physikalischesobjekt.AktuelleInstallation' [FROM PhysikalischesObjekt physikalischesObjekt LEFT OUTER JOIN FETCH physikalischesobjekt.AktuelleInstallation installation ]
Stacktrace:
> NHibernate.dll!NHibernate.Hql.Ast.ANTLR.Util.LiteralProcessor.LookupConstant(NHibernate.Hql.Ast.ANTLR.Tree.DotNode node) Zeile 81 C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.Tree.DotNode.Resolve(bool generateJoin, bool implicitJoin, string classAlias, NHibernate.Hql.Ast.ANTLR.Tree.IASTNode parent) Zeile 208 C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.Tree.FromReferenceNode.Resolve(bool generateJoin, bool implicitJoin, string classAlias) Zeile 58 C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.CreateFromJoinElement(NHibernate.Hql.Ast.ANTLR.Tree.IASTNode path, NHibernate.Hql.Ast.ANTLR.Tree.IASTNode alias, int joinType, NHibernate.Hql.Ast.ANTLR.Tree.IASTNode fetchNode, NHibernate.Hql.Ast.ANTLR.Tree.IASTNode propertyFetch, NHibernate.Hql.Ast.ANTLR.Tree.IASTNode with) Zeile 681 C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.joinElement() Zeile 3955 + 0x3c Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElement() Zeile 3617 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElementList() Zeile 3391 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromClause() Zeile 3308 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery() Zeile 1645 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query() Zeile 1510 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectStatement() Zeile 536 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.statement() Zeile 435 + 0xc Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate() Zeile 590 + 0x1b Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(string collectionRole) Zeile 449 + 0x12 Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(System.Collections.Generic.IDictionary<string,string> replacements, bool shallow, string collectionRole) Zeile 354 + 0x13 Bytes C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(System.Collections.Generic.IDictionary<string,string> replacements, bool shallow) Zeile 72 C#
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(NHibernate.Hql.Ast.ANTLR.Tree.IASTNode ast, string queryIdentifier, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> filters, NHibernate.Engine.ISessionFactoryImplementor factory) Zeile 43 + 0xa3 Bytes Unknown
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(string queryString, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> filters, NHibernate.Engine.ISessionFactoryImplementor factory) Zeile 21 + 0x3a Bytes C#
NHibernate.dll!NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(string hql, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters, NHibernate.Engine.ISessionFactoryImplementor factory) Zeile 24 + 0x99 Bytes C#
NHibernate.dll!NHibernate.Engine.Query.HQLStringQueryPlan.HQLStringQueryPlan(string hql, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters, NHibernate.Engine.ISessionFactoryImplementor factory) Zeile 16 + 0x3e Bytes C#
NHibernate.dll!NHibernate.Engine.Query.HQLStringQueryPlan.HQLStringQueryPlan(string hql, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters, NHibernate.Engine.ISessionFactoryImplementor factory) Zeile 14 C#
NHibernate.dll!NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(string queryString, bool shallow, System.Collections.Generic.IDictionary<string,NHibernate.IFilter> enabledFilters) Zeile 61 + 0x5b Bytes C#
NHibernate.dll!NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(string query, bool shallow) Zeile 304 + 0x87 Bytes C#
NHibernate.dll!NHibernate.Impl.AbstractSessionImpl.CreateQuery(string queryString) Zeile 283 + 0x3b Bytes C#
Is there a problem using alias like this in Hql? Is there a Syntax that disallows to use the same alias name as the entity name? It seems that Nhibernate tries find a persister for the alias name which doesn't work, obviously.
The alias you used are not the same: "physikalischesObjekt" and "physikalisachesobjekt".
I need IQueryable inside my business logic assembly based on Domain entities. I want to use auto-mapper for this purposes due to big amount of similar entities.
Works:
_repository.GetList<AgentDto>()
.Select(dto => new Agent{Login = dto.Login, Password = dto.Password})
.Where(...).ToList();
Does not work (I could not place Where (another assembly) before Select):
_repository.GetList<AgentDto>()
.Select(dto => ToAgent(dto))
.Where(...).ToList();
private Agent ToAgent(AgentDto dto)
{
return new Agent{Login = dto.Login, Password = dto.Password};
}
Exception:
System.NotSupportedException was caught
Message=CustomerInfo.Domain.Support.Agent ToAgent(CustomerInfo.DAL.DTO.AgentDto)
Source=NHibernate
StackTrace:
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMemberExpression(MemberExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.Visit(Expression expression, VisitorParameters parameters)
at NHibernate.Linq.Visitors.QueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
at Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
at NHibernate.Linq.Visitors.QueryModelVisitor.Visit()
at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root)
at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory)
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source, Expression`1 predicate)
at CustomerInfo.BLL.Authentication.AgentManagementService.ValidateAgent(String agentLogin, String password) in D:\Projects\CustomerInfo\CustomerInfo.BLL\Authentication\AgentManagementService.cs:line 49
InnerException:
You need to think about how NHibernate Linq provider works. It cannot process everything you throw at it. NHibernate's Linq provider transforms lambda expressions to HQL and eventually to SQL. There is only a limited subset of expressions that it can support. Anything you enter as an expression must be convertible to SQL and execute in the database engine itself.
NHibernate Linq provider is extensible. If you need to use some expressions that aren't supported by NH Linq provider, and you think that they can be represented in SQL, you can write your own extension.
However, your case is pretty simple. You don't need to extend NHibernate to do it. NHibernate Linq provider doesn't support your expression, but Linq to objects does. Just reverse the order in your query, and it should work as expected:
_repository.GetList<AgentDto>()
.Where(...).ToList()
.Select(dto => ToAgent(dto)).ToList();
.ToList() after .Where() will execute NHibernate query and return a list of AgentDto objects. .Select method after that is in fact executing as Linq to objects - on a list of AgentDto objects in memory.
I think if you simply put the Where before the Select you'll be fine.
I am trying some thing like
GetQueryable<Requirement>()
.OrderByDescending( y => y.BidsReceieved.Count() )
.ToList();
but its failing, with exception
Infrastructure.DataAccess.RequirementRepositoryTests.IsOrderbyBidCountWorking' failed: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException : Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [.OrderByDescending[KHM.Domain.Entities.Requirement,System.Int32](NHibernate.Linq.NhQueryable`1[KHM.Domain.Entities.Requirement], Quote((y, ) => (.Count[KHM.Domain.Entities.Bid](y.BidsRecieved, ))), )]
at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()
at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole)
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression)
at Remotion.Data.Linq.QueryableBase`1.GetEnumerator() in :line 0
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
DataAccess\Repositories\RequirementsRepository.cs(49,0): at KHM.Infrastructure.DataAccess.Repositories.RequirementsRepository.Orderbybids()
Infrastructure\DataAccess\RequirementRepositoryTests.cs(115,0): at KHM.IntegrationTests.Infrastructure.DataAccess.RequirementRepositoryTests.IsOrderbyBidCountWorking()
I want to order the requirements based on the no of bids it received.
I'm using linq-to-nhibernate, I am using nhibernate3.1
is BidsReceieved a colleciton?
if so, I think you should use BidsReceieved.Count but not BidsReceieved.Count(). No bracket here.