I am trying to use Npgsql.EntityFramework with the Amazon Redshift database. I've gotten beyond #511 but hit a new error. The following Entity Framework query:
var drugCodes = dbContext.DrugCodes
.Where(d => d.ProductName == "V-CILLIN-K");
produces this sql:
SELECT "Extent1"."CODE", "Extent1"."PRODUCT_NAME", "Extent1"."GENERIC_NAME" FROM "dbo"."DRUG_CODE" AS "Extent1" WHERE E'V-CILLIN-K' = "Extent1"."PRODUCT_NAME"
which results in the following error:
ERROR: 42704: type "e" does not exist
It appears that Redshift does not support the postgresql E' escape string constant.
See source code https://github.com/npgsql/npgsql/blob/master/Npgsql.EntityFramework/SqlGenerators/VisitedExpression.cs line 222
Full Exception:
Test method Minerva.Tests.Models.Entities.MinervaDbContextTest.DrugCodes_ByProductName_ReturnsMany threw exception:
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> Npgsql.NpgsqlException: ERROR: 42704: type "e" does not exist
Result StackTrace:
at Npgsql.NpgsqlState.d__0.MoveNext() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlState.BackendResponse.cs:line 310
at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject(Boolean cleanup) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1158
at Npgsql.ForwardsOnlyDataReader.GetNextRowDescription() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1176
at Npgsql.ForwardsOnlyDataReader.NextResultInternal() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1386
at Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean preparedStatement, NpgsqlRowDescription rowDescription) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1010 at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlCommand.PrepareExecute.cs:line 279 at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlCommand.PrepareExecute.cs:line 234 at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlCommand.PrepareExecute.cs:line 181 at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__6() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__5() at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable1 sequence)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable1 query, Expression queryRoot) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression) at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.Count[TSource](IQueryable1 source)
at Minerva.Tests.Models.Entities.MinervaDbContextTest.DrugCodes_ByProductName_ReturnsMany() in c:\Users\Andrew\Source\Repos\Minerva\Minerva.Tests\Models\Entities\MinervaDbContextTest.cs:line 21
I am trying to use Npgsql.EntityFramework with the Amazon Redshift database. I've gotten beyond #511 but hit a new error. The following Entity Framework query:
produces this sql:
SELECT "Extent1"."CODE", "Extent1"."PRODUCT_NAME", "Extent1"."GENERIC_NAME" FROM "dbo"."DRUG_CODE" AS "Extent1" WHERE E'V-CILLIN-K' = "Extent1"."PRODUCT_NAME"
which results in the following error:
ERROR: 42704: type "e" does not exist
It appears that Redshift does not support the postgresql E' escape string constant.
See source code https://github.com/npgsql/npgsql/blob/master/Npgsql.EntityFramework/SqlGenerators/VisitedExpression.cs line 222
Full Exception:
Test method Minerva.Tests.Models.Entities.MinervaDbContextTest.DrugCodes_ByProductName_ReturnsMany threw exception:
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> Npgsql.NpgsqlException: ERROR: 42704: type "e" does not exist
Result StackTrace:
at Npgsql.NpgsqlState.d__0.MoveNext() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlState.BackendResponse.cs:line 310
at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject(Boolean cleanup) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1158
at Npgsql.ForwardsOnlyDataReader.GetNextRowDescription() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1176
at Npgsql.ForwardsOnlyDataReader.NextResultInternal() in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1386
at Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable
1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean preparedStatement, NpgsqlRowDescription rowDescription) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlDataReader.cs:line 1010 at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlCommand.PrepareExecute.cs:line 279 at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlCommand.PrepareExecute.cs:line 234 at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\dev\TeamCity\buildAgent\work\45caad201a245970\Npgsql\Npgsql\NpgsqlCommand.PrepareExecute.cs:line 181 at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext1 c)at System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed)at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectQuery
1.<>c__DisplayClass7.<GetResults>b__6() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)at System.Data.Entity.Core.Objects.ObjectQuery
1.<>c__DisplayClass7.<GetResults>b__5() at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func1 operation)at System.Data.Entity.Core.Objects.ObjectQuery
1.GetResults(Nullable1 forMergeOption)at System.Data.Entity.Core.Objects.ObjectQuery
1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext()at System.Linq.Enumerable.Single[TSource](IEnumerable
1 source) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable1 sequence)at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable
1 query, Expression queryRoot) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression) at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.Count[TSource](IQueryable1 source)at Minerva.Tests.Models.Entities.MinervaDbContextTest.DrugCodes_ByProductName_ReturnsMany() in c:\Users\Andrew\Source\Repos\Minerva\Minerva.Tests\Models\Entities\MinervaDbContextTest.cs:line 21