ELEMENT example request

Thread is closed for posting
5 posts, 0 answers
  1. Patty Weathington
    Patty Weathington avatar
    4 posts
    Member since:
    May 2007

    Posted 01 Dec 2008 Link to this post

    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
  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 02 Dec 2008 Link to this post

    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.
  3. Patty Weathington
    Patty Weathington avatar
    4 posts
    Member since:
    May 2007

    Posted 02 Dec 2008 Link to this post

    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
  4. Patty Weathington
    Patty Weathington avatar
    4 posts
    Member since:
    May 2007

    Posted 02 Dec 2008 Link to this post

    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.

  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 03 Dec 2008 Link to this post

    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.
Back to Top