Retrieving a single record.

Thread is closed for posting
4 posts, 0 answers
  1. Alfred Ortega
    Alfred Ortega avatar
    193 posts
    Member since:
    May 2005

    Posted 13 Nov 2008 Link to this post

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

    Posted 14 Nov 2008 Link to this post

    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.
  3. Alfred Ortega
    Alfred Ortega avatar
    193 posts
    Member since:
    May 2005

    Posted 14 Nov 2008 Link to this post

    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

  4. Alfred Ortega
    Alfred Ortega avatar
    193 posts
    Member since:
    May 2005

    Posted 14 Nov 2008 Link to this post

    Thanks a ton - the OID thing worked great!

    Al
Back to Top