Query using "null" thows an exception
Posted: 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;
}
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;
}