Query using "null" thows an exception

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
houcha1
Posts: 3
Joined: Wed 04 Mar 2009 14:20

Query using "null" thows an exception

Post by houcha1 » Wed 04 Mar 2009 14:37

I have created an Entity Model and added a partial class to the main entity class (that extends ObjectContext) to do some common data queries.

I have a simple method that executes a Linq query. When I run it, I get an exception "Devart.Data.PostgreSql.PgSqlException: could not determine data type of parameter $1". If I change the null to string.Empty it succeeds (but I need to check for null, otherwise I would get an exception in the StartsWith method that follows the null check. Am I doing something wrong (I'm new to this).

public IEnumerable FindClinicians(Clinicians match)
{
var patients =
from clinician in Clinicians
where ((match.UserName == null) || clinician.UserName.StartsWith(match.UserName)) &&
((match.ClinicianId == Guid.Empty) || clinician.ClinicianId.Equals(match.ClinicianId))
select clinician;

// Accessign the enumerator actually executes the query.
patients.GetEnumerator();

return patients;
}

houcha1
Posts: 3
Joined: Wed 04 Mar 2009 14:20

Post by houcha1 » Wed 04 Mar 2009 14:52

In this case I can check for null before executing the query... but how would I do this if I wanted to check "clinician" for null as part of the query?

Code: Select all

public IEnumerable FindClinicians(Clinicians match)
    {
      string userName = match.UserName ?? string.Empty;

      var patients =
        from clinician in Clinicians
        where (clinician.UserName.StartsWith(userName)) &&
              ((match.ClinicianId == Guid.Empty) || clinician.ClinicianId.Equals(match.ClinicianId))
        select clinician;

      // Accessign the enumerator actually executes the query.
      patients.GetEnumerator();

      return patients;
    }

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 05 Mar 2009 14:35

Could you please specify the versions of dotConnect and Entity Developer (if you use it)?
Also, please send me (support * devart * com, subject "EF: null problem") a small test project ilustrating the problem (include the DB script, if possible).

houcha1
Posts: 3
Joined: Wed 04 Mar 2009 14:20

Post by houcha1 » Thu 05 Mar 2009 15:35

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1
Installed Edition: Standard

Devart dotConnect for PostgreSQL 4.0.22.0
Devart Entity Developer 1.0

Also, I sent you the project you requested.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 10 Mar 2009 07:42

Sorry, but there is no test project available yet. Could you please resend it directly to andreyr * devart * com?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 10 Mar 2009 08:01

Sorry, but there is no test project available yet. Could you please resend it directly to andreyr * devart * com?

Post Reply