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

Retrieving a single record.

3 Answers 106 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.
Alfred Ortega
Top achievements
Rank 2
Alfred Ortega asked on 14 Nov 2008, 12:39 AM
There has to be a better way then what I'm doing but I've spent 2 days looking for one and can't find it.  How do I select an single record?  I can't get the IObjectId thing to work (if that is even it's intent I'm not sure).  Currently my work around is to do my Linq query that I know will bring my one record and just break after the first iteration of a foreach loop - ugh. Please tell me what I'm missing here...

Al

3 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 14 Nov 2008, 04:19 PM
Hi Alfred Ortega,

that should not be necessary. First of all, LINQ knows about the First() extension method, so your manual enumeration break should not be necessary. Secondly, the IObjectId is indeed intended to identify a single instance by it's primary key value(s). You can obtain such a value via

IObjectId oid = Database.OID.ParseObjectId(Type,string);

and use the value to fetch the persistent instance in the context of an IObjectScope

MyClass x = (MyClass)scope.GetObjectById(oid);

Hope this clarifies it.
Sincerely yours,
Thomas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alfred Ortega
Top achievements
Rank 2
answered on 14 Nov 2008, 04:33 PM

I looked at First (along with FirstOrDefault, Single and SingleOrDefault) but they all came up as deprecated so I didn't feel comfortable using them.  If First is not deprecated I will gladly use it.

 I will check on the OID this way - the documentation showed it differently using an IObjectIDHelper class but that didn't work.

 

Thanks

0
Alfred Ortega
Top achievements
Rank 2
answered on 15 Nov 2008, 12:42 AM
Thanks a ton - the OID thing worked great!

Al
Tags
General Discussions
Asked by
Alfred Ortega
Top achievements
Rank 2
Answers by
Thomas
Telerik team
Alfred Ortega
Top achievements
Rank 2
Share this question
or