Monday, April 25, 2011

SQL Data Services - querying for null

(This relates to Microsoft's SitkaSoapService, in the service reference at https://database.windows.net/soap/v1/)

I'm using SitkaSoapServiceClient to access my SQL Data Services database by SOAP.

I can query data by passing a linq statement in a string, such as:

Scope scope = new Scope();
scope.AuthorityId = authorityId;
scope.ContainerId = containerId;

using (SitkaSoapServiceClient proxy = GetProxy())
    return proxy.Query(scope, "from e in entities where e[\"FirstName\"] == \"Bob\" select e");

However, I can't figure out how to query for a null property value (i.e. find entities without that property).

I'd expect to be able to say:

return proxy.Query(scope, "from e in entities where e[\"FirstName\"] == null select e");

... but that throws a FaultException<>, saying "The name 'null' could not be found"

Any ideas?

From stackoverflow
  • I'm not familiar with the service you are trying but T-SQL would want something like:

    return proxy.Query(scope, "from e in entities where e[\"FirstName\"] IS null select e");
    
    le dorfier : Except the whole point of linq is to be able to avoid SQL syntax...
    teedyay : Meh, it was worth a try. Doesn't work though...
  • You can check for not null like this:

    where e["FirstName"] >= ""
    

    so the null check becomes:

    where !(e["FirstName"] >= "")
    

    A bit nasty, but it works. Maybe there's a better way, but I can't find it...

0 comments:

Post a Comment