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