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

ELEMENT example request

4 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Patty Weathington
Top achievements
Rank 1
Patty Weathington asked on 01 Dec 2008, 09:06 PM
Could someone post a short snippet showing how to use the ELEMENT OQL statement to get the corresponding C# object?  What is the best way to find an existing object without using IObjectId?

Thanks,
Chris

4 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 02 Dec 2008, 01:23 PM
Hi Patty,

the ELEMENT keyword is not implemented yet.
Really, the best way to retrieve a single instance by its primary key values it to use GetObjectById(). You can create an IObjectId instance by using Database.OID.ParseObjectId(<TYPE>,<STRING>).

All the best,
Thomas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Patty Weathington
Top achievements
Rank 1
answered on 02 Dec 2008, 03:52 PM
Could you provide a few examples of the different ways to get a single object in C#?  I'd like to see how to get object using generic GetOqlQuery, regular GetOqlQuery.  I want to be able to get the object from a query when I don't know the id.   I'm using GetOqlQuery to return IQueryResult and a foreach loop that loops through the correct number of times, but the mpt is always null.

 

IQueryResult result = scope.GetOqlQuery("SELECT a FROM MenuPermissionTypeExtent as a").Execute();

 

 

foreach (MenuPermissionType mpt in result)

 

{

 

    string sd = mpt.Name;

 

}



I can't get the ParseObjectId to work either.  Is the ObjectId the primary key?  How do I get the second parameter to ParseObjectId (without adding it right before like in documentation)

Thanks
0
Patty Weathington
Top achievements
Rank 1
answered on 02 Dec 2008, 07:33 PM

I see why I was having some of the problems.  I had public fields in my class instead of properties.  I've gotten both the GetOqlQueries working.

 

I'd still like to know how to use the ParseObjectId.  I would think it would take the primary key, but it doesn't seem to be case.

0
Thomas
Telerik team
answered on 03 Dec 2008, 05:11 PM
Hi Patty,


assuming that your MenuPermissionType has only one primary key field, you can obtain an IObjectId instance by

IObjectId oid = Database.OID.ParseObjectId(typeof(MenuPermissionType),"123");

This oid can then be used to retrieve the instance with the primary key value 123 from the database.

Greetings,
Thomas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Patty Weathington
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Patty Weathington
Top achievements
Rank 1
Share this question
or