Cannot get object by Id (OIDHelper.ParseObjectId)

Thread is closed for posting
12 posts, 0 answers
  1. aung maw
    aung maw avatar
    18 posts
    Member since:
    Apr 2006

    Posted 13 Apr 2009 Link to this post

    Hi, I'm trying to get an object by its Id as shown but it is not working.   Please assist.  Thanks again.


                IObjectScope scope = ObjectScopeProvider1.ObjectScope();
                FunctionTitle f =  (FunctionTitle) scope.GetObjectById(OIDHelper.ParseObjectId(typeof(FunctionTitle), "3050"));
                Console.Out.WriteLine(f.FunctionDescription);


    Error    128    An object reference is required for the non-static field, method, or property 'Telerik.OpenAccess.OIDHelper.ParseObjectId(System.Type, string)'   








  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 14 Apr 2009 Link to this post

    Hi aung maw,

    The ParseObjectId method is located at the Database.OID class. So the right statement should look like this:
    scope.GetObjectById(Database.OID.ParseObjectId(typeof(FunctionTitle), "3050"))


    All the best,
    Alexander
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. aung maw
    aung maw avatar
    18 posts
    Member since:
    Apr 2006

    Posted 14 Apr 2009 Link to this post

    Dear Alexander, Thanks so much.  IN the documentation it shows as below under "Retrieving Objects by ID" topic. Not so sure that is outdated or needs to be updated. 

    Regards,

    Customer c = (Customer) scope.GetObjectById( OIDHelper.ParseObjectId( null, idString ) );

  4. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 15 Apr 2009 Link to this post

    Hi aung maw,

    Yes, we found this outdated information, it will be fixed soon. Your telerik points have been updated, thank you.

    All the best,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. aung maw
    aung maw avatar
    18 posts
    Member since:
    Apr 2006

    Posted 30 Apr 2009 Link to this post

    Hi, I have a primary key (integer type) and would like to get a report by primary key.  GetObjectById works only when the primary key is varchar.  Is there any way to get by integer value?  Code below doesn't work since primary key is automatically assigned by openacess with integer type.

    Thanks,
    AM.





            public void TestGetReportByPrimaryKey()
            {
                IObjectScope scope = ObjectScopeProvider1.ObjectScope();
                Report r = (Report)scope.GetObjectById(Database.OID.ParseObjectId(null, "1"));
                Console.Out.WriteLine(r.Title);

            }
  6. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 01 May 2009 Link to this post

    Hi aung maw,

    You have to pass the class type to the ParseObjectId method as first parameter:
    public void TestGetReportByPrimaryKey()  
    {  
        IObjectScope scope = ObjectScopeProvider1.ObjectScope();  
        Report r = (Report)scope.GetObjectById(Database.OID.ParseObjectId(typeof(Report), "1"));  
        Console.Out.WriteLine(r.Title);  
    }  
    Null has to be passed only in the case when you are using internal identity.

    Greetings,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. aung maw
    aung maw avatar
    18 posts
    Member since:
    Apr 2006

    Posted 01 May 2009 Link to this post

    Hi Alexander, I'm indeed using internal identity and thus why null was passed as parameter.  Internal identity is integer so not so sure how it work.  Many Thanks,



    Telerik.OpenAccess.Exceptions.InvalidObjectIdException : Invalid OID String: '1': System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at OpenAccessRuntime.DataObjects.OpenAccessOid..ctor(String s)
  8. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 02 May 2009 Link to this post

    Hello aung maw,

    It seems that this is a bug on our side. We will investigate it and tell you if there is a workaround that you can use until the fix is available.

    Sincerely yours,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 05 May 2009 Link to this post

    Hello aung maw,

    In fact this is not a bug but something we do not have described in our documentation. The right way of getting the object by its internal id is:
    public void TestGetReportByPrimaryKey()   
    {   
        IObjectScope scope = ObjectScopeProvider1.ObjectScope();   
        Report r = (Report)scope.GetObjectById(Database.OID.ParseObjectId(null
           scope.Database.GetClassId(typeof(Report)).ToString() + "-" + "1")));   
     
        Console.Out.WriteLine(r.Title);   
    }   
    We are sorry for the inconvenience. Your Telerik points have been updated.

    Regards,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. aung maw
    aung maw avatar
    18 posts
    Member since:
    Apr 2006

    Posted 05 May 2009 Link to this post

    Hi Alexander, thanks as always for your support!
  11. Jason Reimer
    Jason Reimer avatar
    2 posts
    Member since:
    Apr 2010

    Posted 30 Apr 2010 Link to this post

    I sincerely do not mean to be rude, but does anyone on the design development team think this is a clean interface/API for getting by a primary key?  Seriously?

        
        Report r = (Report)scope.GetObjectById(Database.OID.ParseObjectId(null
           scope.Database.GetClassId(typeof(Report)).ToString() + "-" + "1")));   
     
  12. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 04 May 2010 Link to this post

    Hello Jason Reimer,

    We are aware that the API is a bit complex but it cannot be simplified much more due to the different identity types that are supported. Unfortunately I am not able to suggest you a better approach of loading an object with internal identity. In fact the internal identity mechanism is meant to be used only internally by OpenAccess. If you want to load objects by their ids, you should better switch to single field identity. In such case you can do the following:
    Report report = scope.GetObjectById<Report>(new IntIdentity(typeof(Report), 1));
    There are other identity classes (like the IntIdentity) implementing the IObjectId interface that can be used in cases of Guid, string or other types of ids.
    Please let us know if you need more details about migrating to single field identity.

    Kind regards,
    Alexander
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top