db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

Why using one method works and the other doesn't?

Last post 07-18-2008, 01:24 AM by German Viscuso. 3 replies.
Sort Posts: Previous Next
  •  07-17-2008, 01:33 PM 50183

    Why using one method works and the other doesn't?

    Hello everyone, I want to find a person (Comensal class) given any of three attributes. I have this query by example:

    Comensal p = new Comensal();
    if (aCodigoBarras != String.Empty) p.CodigoBarras = aCodigoBarras;
    if (aNumeroUCI != String.Empty) p.IdExpediente = aNumeroUCI;
    if (aCI != String.Empty) p.CI = aCI;
    IObjectSet result = dbPersonas.Get(p);

    Which works really fast, but does not find some persons all the times, I'm still figuring out which set of persons these are. However, this code:

    IList<Comensal> result = dbPersonas.Query<Comensal>(delegate(Comensal ap)
    {
                   return    ap.IdExpediente == aNumeroUCI ||
                               ap.CI == aCI ||
                               ap.CodigoBarras == aCodigoBarras;
     }
     );

     ...does find every single person, though it's significantly slower. Can anyone spot the difference?? Its the same database, same persons, same everything.

    Thanks in advance. 

     

     

     

     

  •  07-17-2008, 01:46 PM 50185 in reply to 50183

    Re: Why using one method works and the other doesn't?

    Hi!

    1. You're checking for empty values in QBE but not the NQ one
    2. NQ might not be running optimized hence the slow speed
    3. You're specifying AND in QBE and OR in NQ
    Goran
  •  07-17-2008, 02:08 PM 50186 in reply to 50185

    Re: Why using one method works and the other doesn't?

    Thanks Goran, the problem was in the default values of boolean fields. There is one which is set to true in the class constructor, and some persons have it false in the DB, hence the odd results. this brings me to a second doubt, how to tell QBE to overlook a boolen field? I mean, if it is false, How do I tell not to look for objects with FALSE value? When I set a a field value is any different than not setting it? Put in another way, is FALSE by default any different than a FALSE purposedly set??

     

    Best regards.
     

  •  07-18-2008, 01:24 AM 50198 in reply to 50186

    Re: Why using one method works and the other doesn't?

    Hi.

    If the boolean field is not a primitive type you can set it to null in the prototype and QBE will overlook it.

    There's a related entry by Patrick here but I don't think the Google translation from German is very good.

    Best.


    German Viscuso ยป db4objects
    W: +1 (650) 515-3615
    F: +1 (650) 240-0421
    M: +1 (650) 863-5474
View as RSS news feed in XML