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

Cannot get object by Id (OIDHelper.ParseObjectId)

11 Answers 201 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.
aung maw
Top achievements
Rank 1
aung maw asked on 13 Apr 2009, 10:51 PM
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)'   








11 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 14 Apr 2009, 07:11 AM
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.
0
aung maw
Top achievements
Rank 1
answered on 14 Apr 2009, 02:39 PM
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 ) );

0
Alexander
Telerik team
answered on 15 Apr 2009, 06:32 AM
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.
0
aung maw
Top achievements
Rank 1
answered on 30 Apr 2009, 10:37 PM
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);

        }
0
Alexander
Telerik team
answered on 01 May 2009, 10:12 AM
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.
0
aung maw
Top achievements
Rank 1
answered on 01 May 2009, 10:31 AM
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)
0
Alexander
Telerik team
answered on 02 May 2009, 03:06 PM
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.
0
Alexander
Telerik team
answered on 05 May 2009, 10:49 AM
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.
0
aung maw
Top achievements
Rank 1
answered on 05 May 2009, 10:55 AM
Hi Alexander, thanks as always for your support!
0
Jason Reimer
Top achievements
Rank 1
answered on 30 Apr 2010, 02:11 PM
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")));   
 
0
Alexander
Telerik team
answered on 04 May 2010, 04:54 PM
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.
Tags
General Discussions
Asked by
aung maw
Top achievements
Rank 1
Answers by
Alexander
Telerik team
aung maw
Top achievements
Rank 1
Jason Reimer
Top achievements
Rank 1
Share this question
or