This is a migrated thread and some comments may be shown as answers.

non string query parameters in OQL?

4 Answers 154 Views
OQL (OQL specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mattc
Top achievements
Rank 2
mattc asked on 16 Jan 2009, 02:24 PM
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

4 Answers, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 20 Jan 2009, 06:49 AM
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.
0
mattc
Top achievements
Rank 2
answered on 20 Jan 2009, 10:41 AM
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



0
Zoran
Telerik team
answered on 20 Jan 2009, 04:17 PM
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.
0
mattc
Top achievements
Rank 2
answered on 21 Jan 2009, 10:23 AM
Hi Zoran

Perfect, thanks for your help and keeping me moving!

Matt
Tags
OQL (OQL specific questions)
Asked by
mattc
Top achievements
Rank 2
Answers by
Zoran
Telerik team
mattc
Top achievements
Rank 2
Share this question
or