Skip to content

Selecting string literals throws Exception with message "42P18: could not determine data type of parameter $1" #60

@fredimachado

Description

@fredimachado

I made a unit test and it's available in my fork: https://github.com/Fredi/EntityFramework6.Npgsql/tree/select_string_literal

[Test]
public void TestProjectionWithStringLiteral()
{
    using (var context = new BloggingContext(ConnectionString))
    {
        context.Database.Log = Console.Out.WriteLine;

        context.Blogs.Add(new Blog { Name = "_" });
        context.SaveChanges();

        var name = "test";

        var results = context.Blogs.Select(b => new
        {
            Id = b.BlogId,
            Name = name
        }).ToList();

        Assert.AreEqual(1, results.Count);
    }
}

Details:

Test Name: TestProjectionWithStringLiteral
Test Outcome: Failed
Result Message:
System.Data.Entity.Core.EntityCommandExecutionException : An error occurred while executing the command definition. See the inner exception for details.
----> Npgsql.PostgresException : 42P18: could not determine data type of parameter $1
Result StandardOutput:
Opened connection to etab-system.etab.local:5432
Executing statement(s):
select count() from pg_catalog.pg_database where datname = 'npgsql_tests_ef6'
Connection closed
Executing statement(s):
SELECT "GroupBy1"."A1" AS "C1" FROM (SELECT CAST (count(1) AS int4) AS "A1" FROM "dbo"."__MigrationHistory" AS "Extent1" WHERE "Extent1"."ContextKey" = $1) AS "GroupBy1"
Parameters:
$1: EntityFramework6.Npgsql.Tests.BloggingContext
Connection closed
Executing statement(s):
SELECT "Project1"."C1", "Project1"."MigrationId", "Project1"."Model", "Project1"."ProductVersion" FROM (SELECT "Extent1"."MigrationId", "Extent1"."Model", "Extent1"."ProductVersion", 1 AS "C1" FROM "dbo"."__MigrationHistory" AS "Extent1" WHERE "Extent1"."ContextKey" = $1) AS "Project1" ORDER BY "Project1"."MigrationId" DESC LIMIT 1
Parameters:
$1: EntityFramework6.Npgsql.Tests.BloggingContext
Connection closed
Executing statement(s):
SELECT "Extent1"."BlogId", "Extent1"."Name", "Extent1"."IntComputedValue", "Extent1"."User_Id" FROM "dbo"."Blogs" AS "Extent1"
Connection closed
Executing statement(s):
SELECT "Extent1"."PostId", "Extent1"."Title", "Extent1"."Content", CAST ("Extent1"."Rating" AS int2) AS "C1", "Extent1"."CreationDate", "Extent1"."VarbitColumn", "Extent1"."BlogId" FROM "dbo"."Posts" AS "Extent1"
Connection closed
Opened connection to etab-system.etab.local:5432
Executing statement(s):
select count(
) from pg_catalog.pg_database where datname = 'npgsql_tests_ef6'
Connection closed
Opened connection at 12/12/2016 10:18:01 -02:00

SELECT "GroupBy1"."A1" AS "C1" FROM (SELECT CAST (count(1) AS int4) AS "A1" FROM "dbo"."__MigrationHistory" AS "Extent1" WHERE "Extent1"."ContextKey" = @p__linq__0) AS "GroupBy1"

-- p__linq__0: 'EntityFramework6.Npgsql.Tests.BloggingContext' (Type = Object)

-- Executing at 12/12/2016 10:18:01 -02:00

Executing statement(s):
SELECT "GroupBy1"."A1" AS "C1" FROM (SELECT CAST (count(1) AS int4) AS "A1" FROM "dbo"."__MigrationHistory" AS "Extent1" WHERE "Extent1"."ContextKey" = $1) AS "GroupBy1"
Parameters:
$1: EntityFramework6.Npgsql.Tests.BloggingContext
-- Completed in 1 ms with result: NpgsqlDataReader

Connection closed
Closed connection at 12/12/2016 10:18:01 -02:00

Opened connection at 12/12/2016 10:18:01 -02:00

SELECT "Project1"."C1", "Project1"."MigrationId", "Project1"."Model", "Project1"."ProductVersion" FROM (SELECT "Extent1"."MigrationId", "Extent1"."Model", "Extent1"."ProductVersion", 1 AS "C1" FROM "dbo"."__MigrationHistory" AS "Extent1" WHERE "Extent1"."ContextKey" = @p__linq__0) AS "Project1" ORDER BY "Project1"."MigrationId" DESC LIMIT 1

-- p__linq__0: 'EntityFramework6.Npgsql.Tests.BloggingContext' (Type = Object)

-- Executing at 12/12/2016 10:18:01 -02:00

Executing statement(s):
SELECT "Project1"."C1", "Project1"."MigrationId", "Project1"."Model", "Project1"."ProductVersion" FROM (SELECT "Extent1"."MigrationId", "Extent1"."Model", "Extent1"."ProductVersion", 1 AS "C1" FROM "dbo"."__MigrationHistory" AS "Extent1" WHERE "Extent1"."ContextKey" = $1) AS "Project1" ORDER BY "Project1"."MigrationId" DESC LIMIT 1
Parameters:
$1: EntityFramework6.Npgsql.Tests.BloggingContext
-- Completed in 1 ms with result: NpgsqlDataReader

Connection closed
Closed connection at 12/12/2016 10:18:01 -02:00

Opened connection at 12/12/2016 10:18:01 -02:00

Beginning transaction with isolation level Unspecified
Started transaction at 12/12/2016 10:18:01 -02:00

INSERT INTO "dbo"."Blogs"("Name","User_Id") VALUES (@p_0,NULL) RETURNING "BlogId","IntComputedValue"

-- p_0: '_' (Type = Object, IsNullable = false)

-- Executing at 12/12/2016 10:18:01 -02:00

Executing statement(s):
INSERT INTO "dbo"."Blogs"("Name","User_Id") VALUES ($1,NULL) RETURNING "BlogId","IntComputedValue"
Parameters:
$1: _
-- Completed in 2 ms with result: NpgsqlDataReader

Commit transaction
Committed transaction at 12/12/2016 10:18:01 -02:00

Connection closed
Closed connection at 12/12/2016 10:18:01 -02:00

Opened connection at 12/12/2016 10:18:01 -02:00

SELECT "Extent1"."BlogId", @p__linq__0 AS "C1" FROM "dbo"."Blogs" AS "Extent1"

-- p__linq__0: 'test' (Type = Object)

-- Executing at 12/12/2016 10:18:01 -02:00

Executing statement(s):
SELECT "Extent1"."BlogId", $1 AS "C1" FROM "dbo"."Blogs" AS "Extent1"
Parameters:
$1: test
-- Failed in 2 ms with error: 42P18: could not determine data type of parameter $1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions