non string query parameters in OQL?

5 posts, 0 answers
  1. mattc
    mattc avatar
    21 posts
    Member since:
    Aug 2007

    Posted 16 Jan 2009 Link to this post

    Hello

    I'm trying to pick up OQL and ORM at the moment and going a bit slow.

    I've reverse mapped some classes from a database table and have written a couple of functions to add rows and delete rows, all good.

    Now I'm trying to write a OQL statement to pick one row out.
    Think the trouble is that both the fields in the table in wuestion are of type Guid.

    Im assuming I need to pass a guid in my query but not sure I do this as seem to have gone back to writing text strings to query the database with?

    Any help getting going much appreciated, I'm nearly there with my first ORM! :)

    Thanks

    Matt
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 20 Jan 2009 Link to this post

    Hi Matt,

        Retrieving single field with no filtering parameters is not implemented in OQL yet. We will have this functionality in one of our next releases and until then I can recommend you to workaround this using Linq query like:   
                        var result = (from a in scope.Extent<MyGuidClass>()
                                              select a).FirstOrDefault();

       I also would like to introduce to you our Knowledge-Base. It should serve you to advance with OpenAccess more quickly.
      I hope this was helpful and I’m looking forward for your feedback.


    Best wishes,
    Zoran
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. mattc
    mattc avatar
    21 posts
    Member since:
    Aug 2007

    Posted 20 Jan 2009 Link to this post

    Hi Zoran.
    Thanks for replying to this thread.
    I don't think I explained my problem very well.

    what I am trying to do is select some rows from my database based on a parameter. Here's what I have:

    Dim result As IQueryResult = scope.GetOqlQuery("SELECT * FROM PicExtent o WHERE o.PicID = '2d6f9b4f-ab32-4b62-b4a3-6c2c43128687'").Execute

    this works fine if I just use SELECT * FROM PicExtent so I know all the rest is working.
    The problem is that the database field PicID is a guid and as I'm back to writing text query strings again it doesn't work. There is obviously no implicit type conversion as I get the following error if I run it:

    "The types System.Guid of o.PicID and System.Char are not compatible."

    Fair enough! So the how to get different types into my query string?

    I need to use OQL at the moment as the server I will be running on is .NET framework 2.0

    Many thanks

    Matt



  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 20 Jan 2009 Link to this post

    Hello Matt,

          I think I see the source of your problem now and there is a quite simple solution for it. The Guid can not be passed the way you were doing it, because OQL treats it like an array of chars. Since you have the access to the required Guid though, you need to take advantage of the parametrized OQL queries where you can pass the desired Guid as a parameter to the Execute() function. To make it more clear here is how your query should be constructed:
    Dim result As IQueryResult = scope.GetOqlQuery("SELECT * FROM PicExtent o WHERE o.PicID = $1).Execute(new Guid("2d6f9b4f-ab32-4b62-b4a3-6c2c43128687"))

    Hope this solves your problem and we are looking forward to provide you with any additional help required.

    Greetings,
    Zoran
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. mattc
    mattc avatar
    21 posts
    Member since:
    Aug 2007

    Posted 21 Jan 2009 Link to this post

    Hi Zoran

    Perfect, thanks for your help and keeping me moving!

    Matt
Back to Top
DevCraft banner