Page 1 of 1
EF with predicates testing nullable types fail
Posted: Wed 10 Apr 2013 13:33
by ACassells
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.
Re: EF with predicates testing nullable types fail
Posted: Fri 12 Apr 2013 13:15
by Shalex
Thank you for your report. We have reproduced and are investigating the issue.
Re: EF with predicates testing nullable types fail
Posted: Wed 17 Apr 2013 10:16
by Shalex
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))
Re: EF with predicates testing nullable types fail
Posted: Thu 18 Apr 2013 14:53
by Shalex
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.