Page 1 of 1

Query using "null" thows an exception

Posted: Wed 04 Mar 2009 14:37
by houcha1
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;
}

Posted: Wed 04 Mar 2009 14:52
by houcha1
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;
    }

Posted: Thu 05 Mar 2009 14:35
by AndreyR
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).

Posted: Thu 05 Mar 2009 15:35
by houcha1
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.

Posted: Tue 10 Mar 2009 07:42
by AndreyR
Sorry, but there is no test project available yet. Could you please resend it directly to andreyr * devart * com?

Posted: Tue 10 Mar 2009 08:01
by AndreyR
Sorry, but there is no test project available yet. Could you please resend it directly to andreyr * devart * com?