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.
Related
When I use UPDATE query to update a value to NUMBER datatype field i get data type mismatch error
my code :
com.CommandText = "UPDATE register SET price_reg=#price_reg,rprice_reg=#rprice_reg,ipprice_reg=#ipprice_reg,mprice_reg=#mprice_reg,totalp_reg=#totalp_reg,operatormali_reg=#operatormali_reg,noedaryaft_reg=#noedaryaft_reg,datedaryaft_reg=#datedaryaft_reg WHERE id_reg='" & Label58.Text & "' "
com.Parameters.AddWithValue("#price_reg", TextBox12.Text)
com.Parameters.AddWithValue("#rprice_reg", TextBox11.Text)
com.Parameters.AddWithValue("#ipprice_reg", TextBox13.Text)
com.Parameters.AddWithValue("#mprice_reg", TextBox14.Text)
com.Parameters.AddWithValue("#totalp_reg", TextBox15.Text)
com.Parameters.AddWithValue("#operatormali_reg", username)
com.Parameters.AddWithValue("#noedaryaft_reg", ComboBox1.Text)
com.Parameters.AddWithValue("#datedaryaft_reg", TextBox16.Text)
com.ExecuteNonQuery()
5 first parameter is NUMBER datatype in my access database
i try this for send parameters too :
com.Parameters.AddWithValue("#price_reg", convert.toint32(TextBox12.Text))
also i try this :
com.Parameters.AddWithValue("#price_reg", Cdec(TextBox12.Text))
also i try add :
com.CommandText = "UPDATE register SET price_reg=#price_reg,rprice_reg=#rprice_reg,ipprice_reg=#ipprice_reg,mprice_reg=#mprice_reg,totalp_reg=#totalp_reg,operatormali_reg=#operatormali_reg,noedaryaft_reg=#noedaryaft_reg,datedaryaft_reg=#datedaryaft_reg WHERE id_reg='" & Label58.Text & "' "
com.Parameters.Add("#price_reg", OleDbType.Integer)
com.Parameters("#price_reg").Value = CInt(TextBox12.Text)
com.Parameters.Add("#rprice_reg", OleDbType.Integer)
com.Parameters("#rprice_reg").Value = CInt(TextBox11.Text)
com.Parameters.Add("#ipprice_reg", OleDbType.Integer)
com.Parameters("#ipprice_reg").Value = CInt(TextBox13.Text)
com.Parameters.Add("#mprice_reg", OleDbType.Integer)
com.Parameters("#mprice_reg").Value = CInt(TextBox14.Text)
com.Parameters.Add("#totalp_reg", OleDbType.Integer)
com.Parameters("#totalp_reg").Value = CInt(TextBox15.Text)
com.Parameters.AddWithValue("#operatormali_reg", username)
com.Parameters.AddWithValue("#noedaryaft_reg", ComboBox1.Text)
com.Parameters.AddWithValue("#datedaryaft_reg", TextBox16.Text)
com.ExecuteNonQuery()
but same error
error msg :
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217913
Message="Data type mismatch in criteria expression."
Source="Microsoft JET Database Engine"
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at asiatech_managment.Form1.ToolStripButton23_Click(Object sender, EventArgs e) in C:\Users\pc1\Documents\Visual Studio 2008\Projects\asiatech-managment\asiatech-managment\Form1.vb:line 360 at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at asiatech_managment.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
InnerException:
thanks for your answers
The error said
Message="Data type mismatch in criteria expression."
My Question is what is the datatype of your id_reg? is it an INT? if yes then do something like this.
change your
WHERE id_reg='" & Label58.Text & "' "
to
WHERE id_reg=" & Label58.Text
Im trying to change a PDF file with the PDFBox Library in vb.net,
evrything went fine until i was trying to save the PDF, it crashes with the following stacktrace:
org.apache.pdfbox.exceptions.COSVisitorException wurde nicht behandelt.
HResult=-2146233088
Message=java.security.NoSuchAlgorithmException: class configured for MessageDigest(provider: SUN)cannot be found.
Message (Exception)=java.security.NoSuchAlgorithmException: class configured for MessageDigest(provider: SUN)cannot be found.
Source=pdfbox-1.8.7
Source (Exception)=pdfbox-1.8.7
StackTrace:
bei org.apache.pdfbox.pdfwriter.COSWriter.write(PDDocument doc)
bei org.apache.pdfbox.pdmodel.PDDocument.save(OutputStream output)
bei org.apache.pdfbox.pdmodel.PDDocument.save(File file)
bei org.apache.pdfbox.pdmodel.PDDocument.save(String fileName)
bei PDFAnfertigen.Module1.TextAusPDFAuslesen(String pPDFPfad) in C:\Users\fengels\Documents\Visual Studio 2013\Projects\PDFAnfertigen\PDFAnfertigen\Module1.vb:Zeile 44.
bei PDFAnfertigen.Module1.Main() in C:\Users\fengels\Documents\Visual Studio 2013\Projects\PDFAnfertigen\PDFAnfertigen\Module1.vb:Zeile 12.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
InnerException: java.security.NoSuchAlgorithmException
HResult=-2146233088
Message=class configured for MessageDigest(provider: SUN)cannot be found.
Message (Exception)=class configured for MessageDigest(provider: SUN)cannot be found.
Source=IKVM.OpenJDK.Core
Source (Exception)=IKVM.OpenJDK.Core
StackTrace:
bei sun.security.jca.GetInstance.getInstance(String type, Class clazz, String algorithm)
bei java.security.Security.getImpl(String , String , String )
bei java.security.MessageDigest.getInstance(String algorithm)
bei org.apache.pdfbox.pdfwriter.COSWriter.write(PDDocument doc)
InnerException: java.lang.ClassNotFoundException
HResult=-2146233088
Message=sun.security.provider.MD5
Message (Exception)=sun.security.provider.MD5
Source=IKVM.Runtime
Source (Exception)=IKVM.Runtime
StackTrace:
bei IKVM.NativeCode.java.lang.Class.forName0(String name, Boolean initialize, ClassLoader loader)
bei java.lang.Class.forName0(String , Boolean , ClassLoader )
bei java.lang.Class.forName(String className, CallerID )
bei java.security.Provider.Service.getImplClass()
InnerException:
I have no idea what this means and googling it ain´t that effective, this is my Code, even i think it has nothing to do with it
Dim objPDFDokument As PDDocument = PDDocument.load(pPDFPfad)
Do
eingefügt = False
While intSeite < objPDFDokument.getDocumentCatalog.getAllPages.size
Dim Dateipfad() As String = NachDateiZuordnungSuchen(intSeite, pPDFPfad)
If Dateipfad IsNot Nothing Then
For Each strDateipfad As String In Dateipfad
If Path.GetExtension(strDateipfad).Equals(".pdf") Then
Dim objPDFeinfuegDatei As PDDocument = LadePdf(strDateipfad)
For i As Integer = 0 To objPDFeinfuegDatei.getDocumentCatalog.getAllPages.size - 1
eingefügt = True
intSeite += 1
objPDFDokument = FuegeSeiteEin(objPDFDokument, objPDFeinfuegDatei, intSeite)
Next
End If
Next
End If
intSeite += 1
End While
Loop Until eingefügt = False
objPDFDokument.save(Path.Combine(Path.GetDirectoryName(pPDFPfad), "test.pdf"))
objPDFDokument.close()
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 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.
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.