The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Query.Where

Last post 09-18-2007, 5:17 AM by mbevins1. 6 replies.
Sort Posts: Previous Next
  •  09-17-2007, 9:38 AM 5137

    Query.Where

    Hello, I am new to Entityspaces and am trying to figure out a basic query that would return one row.  Am I doing something wrong, is the   XXXX.Query.Where(XXXX.Query.XX ==) only for primary key columns?  Basically, the first query below runs fine using the primary key column however, the second one never returns anything even though it should return the same data as the first one.
      
    Code:
                BusinessObjects.Communication comm = new BusinessObjects.Communication();
                //ID = Primary Key
                comm.Query.Where(comm.Query.Id == 5);
    
                //Returns correct data
                if (comm.Query.Load())
                {
                    label1.Text = comm.DeviceId.ToString(); //Return "1966"
                }
    
                //Device = Index
                comm = new BusinessObjects.Communication();
                comm.Query.Where(comm.Query.DeviceId == "1966");
    
                //Returns Nothing???
                if (comm.Query.Load())
                {
                    label1.Text = comm.DeviceId.ToString();
                }
  •  09-17-2007, 10:13 AM 5142 in reply to 5137

    Re: Query.Where

    You can use the dynamic query against all columns. Try this, after you query access this  comm.Query.es.LastQuery and look at the SQL. I don't know what type of column DeviceId is but perhaps you don't want quotes around "1966" ?  You can definitely use the dynamic query on all columns in complex ways, it's one of the best things about ES.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-18-2007, 4:10 AM 5160 in reply to 5142

    Re: Query.Where

    I added a watch to the comm.Query.es.LastQuery and it appears to have the correct SQL ("SELECT * FROM [communication] WHERE ([device_id] = @device_id1 )).  Also, the device_id is a varchar.  Is there anything else I could be doing wrong?  Is this a limitition of the trial version?
  •  09-18-2007, 4:31 AM 5161 in reply to 5160

    Re: Query.Where

    Hi

    It looks like you're using a single entity object as the query base rather than an EntityCollection.  While this shouldn't present a problem (AFAIK) it may present issues if more than one record is found using the query (as you would be trying to load a collection into a single entity).

    Couple of things I would check. 

    Firstly, is there an exception/error being thrown by the second call to load (if you've got any kind of global exception handling it may be 'hiding' the exception)?

    Secondly, have you confirmed what the database returns when you run the query on the DB directly (Select * From [communication] WHERE device_id="1966" ) - is it a single record, a number of records, no records? (I know what you're expecting it to return, but it's worth validating that against the DB just in case)

    As Mike says, there shouldn't be any difference between query methods but if there is a possibility of a query returning > 1 record I would use a collection rather than a single entity

    Hope that helps

    Martin

  •  09-18-2007, 5:01 AM 5162 in reply to 5161

    Re: Query.Where

    Thanks for your response, I do not know why I didn't try querying the DB first.  For some reason this appears to be a sqlce 3.0 issue ( I don't have this problem in 2).  When I do a select it returns nothing however if I use LIKE '%1966' it does return the correct row.  This is strange because I am positive there is no space in front of the is.
  •  09-18-2007, 5:04 AM 5163 in reply to 5162

    Re: Query.Where

    Hi

    Don't worry - sometimes it's easy to skip things like that as you know what should be there - at least you know now.

    As for the potential leading space - if you want to check for it's presence you could always SELECT the LEN() of the field to see what that produces - or TRIM() that field in the entire DB just in case it has introduced some leading/trailing spaces throughout etc - might save you some headaches in the future ;)

    Cheers

    Martin

  •  09-18-2007, 5:17 AM 5164 in reply to 5163

    Re: Query.Where

    Thanks again, I'll post this new problem in ms sqlce group since I am not sure what is going on.  A len() does return 4 so I am not sure why LIKE '%1966' works where = '1966' doesn't?

View as RSS news feed in XML