Linq query with 2 criteria fails

Posts   
 
    
Burt52
User
Posts: 10
Joined: 01-Mar-2009
# Posted on: 02-Mar-2009 04:44:28   

Hello, The first 2 linq queries below work okay. The 3rd one fails and generates the error message below. It seems it's okay as long as I use only one criteria. When there are 2 criteria it fails. I tried using "AndAlso" as well, and the 3rd query still failed. Thanks

RuntimeBuild="01162009" RuntimeVersion="2.6.0.0"

'Query 1: This one works

Dim user_id As String = "ladymach" Dim pwd As String = "0434" Dim lmd As New LinqMetaData Dim staffmember = (From st In lmd.Staff _ Where st.Pwd = pwd _ Select st).First

'Query 2: This one works, too. Dim user_id As String = "ladymach" Dim pwd As String = "0434" Dim lmd As New LinqMetaData Dim staffmember = (From st In lmd.Staff _ Where st.UserId = user_id _ Select st).First

'Query 3: This one fails and generates the message below: Dim user_id As String = "ladymach" Dim pwd As String = "0434" Dim lmd As New LinqMetaData Dim staffmember = (From st In lmd.Staff _ Where st.UserId = user_id _ And st.Pwd = pwd _ Select st).First

HERE IS THE DDL of the queried table:

CREATE TABLE [dbo].[Staff]( [staff_id] nchar NOT NULL, [staff_name] nvarchar NOT NULL, [email] nvarchar NOT NULL, [user_group] [tinyint] NULL, [pwd] varchar NULL, [user_id] varchar NULL, CONSTRAINT [PK_Staff] PRIMARY KEY NONCLUSTERED ( [staff_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]

HERE IS THE ERROR MESSAGE:

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException was unhandled Message="An exception was caught during the execution of a retrieval query: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception." QueryExecuted=" Query: SELECT TOP 1 [LPLA_1].[staff_id] AS [StaffId], [LPLA_1].[staff_name] AS [StaffName], [LPLA_1].[email] AS [Email], [LPLA_1].[user_group] AS [UserGroup], [LPLA_1].[pwd] AS [Pwd], [LPLA_1].[user_id] AS [UserId] FROM [EDSTimeSheet].[dbo].[Staff] [LPLA_1] WHERE ( ( ( ( ( [].[LPFA_3] = @LPFA_31))))) Parameter: @LPFA_31 : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True. " RuntimeBuild="01162009" RuntimeVersion="2.6.0.0" Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction, IEntityCollection collectionToFill, Boolean allowDuplicates, IEntityFields fieldsUsedForQuery, IFieldPersistenceInfo[] fieldPersistenceInfos) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetMulti(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IEntityFactory entityFactoryToUse, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteEntityProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.First[TSource](IQueryable1 source) at StaffHoursConsoleLL.Module1.GetStaffIDUserGroup() in C:\Users\Burton Roberts\Documents\LLBLGen Pro Projects\StaffHoursConsoleLL\StaffHoursConsoleLL\StaffHoursConsoleLL\Module1.vb:line 78 at StaffHoursConsoleLL.Module1.Main() in C:\Users\Burton Roberts\Documents\LLBLGen Pro Projects\StaffHoursConsoleLL\StaffHoursConsoleLL\StaffHoursConsoleLL\Module1.vb:line 15 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: System.Data.SqlClient.SqlException Class=15 ErrorCode=-2146232060 LineNumber=1 Message="An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name." Number=1038 Procedure="" Server="(local)" Source=".Net SqlClient Data Provider" State=4 StackTrace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) InnerException:

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 02-Mar-2009 09:47:51   

Use AndAlso, not And. And will result in a bitwise and in the Expression tree and it's not possible to detect the real meaning.

Frans Bouma | Lead developer LLBLGen Pro
Burt52
User
Posts: 10
Joined: 01-Mar-2009
# Posted on: 02-Mar-2009 16:55:37   

Thanks. I thought I had tried that, but I must have been mistaken. Your suggestion works.