EF with predicates testing nullable types fail

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
ACassells
Posts: 4
Joined: Fri 05 Apr 2013 15:36

EF with predicates testing nullable types fail

Post by ACassells » Wed 10 Apr 2013 13:33

When I run dotConnect Postgres with Entity Framework and have predicates that check against nullable types the error
{"could not determine data type of parameter $1"}
occurs.

As an example with the code

Code: Select all

 TestContext context = new TestContext();

            int? test = 1;

            var testListPass = context.TestEntities.Where(e => e.TestEntityID == test).ToList();

            var testListFail = context.TestEntities.Where(e => (test.HasValue && e.TestEntityID == test)).ToList();
The code fails on the assignment of testListFail. This is obviously a trivial example but we have much more complicated query expressions which work on the MS EF stack and fail when I port them to the postgres application. I have rewritten these so that they work but they become much uglier with lots of null checks and not as fluent.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF with predicates testing nullable types fail

Post by Shalex » Fri 12 Apr 2013 13:15

Thank you for your report. We have reproduced and are investigating the issue.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF with predicates testing nullable types fail

Post by Shalex » Wed 17 Apr 2013 10:16

The bug with SQL generation for the HasValue property of the Nullable<T> variable in LINQ to Entities queries is fixed. We will post here when the corresponding build of dotConnect for PostgreSQL is available for download. As a temporary workaround, please add "Protocol=Ver20;" to your connection string.

Be aware that there is a UseCSharpNullComparisonBehavior configuration option which allows to obtain a correct comparison of the nullable columns with parameters:

Code: Select all

  var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
  config.QueryOptions.UseCSharpNullComparisonBehavior = true;

  string stringValue = "test";
  using (PostgreEntities context = new PostgreEntities(connectionString)) {
    var query = context.Depts.Where(e => e.Dname == stringValue).ToList();
  }
produces the following SQL

Code: Select all

SELECT 
"Extent1".deptno,
"Extent1".dname,
"Extent1".loc
FROM public.dept AS "Extent1" 
WHERE ("Extent1".dname = :p__linq__0) OR (("Extent1".dname IS NULL) AND (:p__linq__0 IS NULL))

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF with predicates testing nullable types fail

Post by Shalex » Thu 18 Apr 2013 14:53

New build of dotConnect for PostgreSQL 6.6.224 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=3&t=26908.

Post Reply