NoSuchObjectException and false references

Thread is closed for posting
2 posts, 0 answers
  1. Miika
    Miika avatar
    28 posts
    Member since:
    Jun 2012

    Posted 23 May 2013 Link to this post

    Hi there,

    I think I may have found a bit of a problem in the OpenAccess ORM, although this might be a fairly rare case. Firstly, some background. We have our database tables defined as normal, but for security reasons (which were defined well before I came to the company...) database access is always performed through so called "Row Level Security Views". These views restrict the returned results to only those accessible to a particular user.

    So in our example case, we have a Users table, and a Responsibilities table, both are populated, with Responsibilities table containing a foreign key linking the two. A user can be "made passive" (read deleted without actually removing the data), with the effect that the RLSView will no longer return this user. If we do a search for all responsibilities, and then iterate through them and access the rlsvResponsibility.rlsvUser navigational property, it throws an NoSuchObjectException. I understand that it does this because it -expects- the object to be there (its defined as a foreign key on the table itself), but no user object is returned because of the security restrictions. I would think the expected behaviour would be that it returns null, rather than throwing an exception, no?

    var responsibilities = context.rlsvResponsibilities.Where(p => p.Important == true)
    foreach (var value in responsibilities.ToList())
        // try to access value.rlsvUser property, NoSuchObject exception is thrown.

    Telerik.OpenAccess.Exceptions.NoSuchObjectException: No row for Company.OurDatabase.DataAccess.RlsvUsers ('Common'.'rlsvUsers') GenericOID@ffffaa38 RlsvUsers UserID=545 NOTRES 
       at OpenAccessRuntime.ExceptionWrapper.Throw()
       at OpenAccessRuntime.DataObjects.PCStateMan.handleException(Exception x)
       at OpenAccessRuntime.DataObjects.PCStateMan.getObjectFieldImp(PersistenceCapable pc, FieldMetaData fmd, Object currentValue)
       at Company.OurDatabase.DataAccess.RlsvResponsibilities.OpenAccessEnhancedGet_rlsvUsers(RlsvResponsibilities owner)

    The example is a greatly simplified version of the case that actually produced the error, but hopefully this is enough information to see whats going on.

    Environment is:
    SQL Server (v. 10.0.1600)
    latest version of Telerik OpenAccess (I think 2013 Q3 SP1?)

    Miika Langille
  2. Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 27 May 2013 Link to this post

    Hi Miika,

    Telerik OpenAccess ORM allows you to work in both ways: to return null when a record is not found or throw an exception. The behavior is controlled by setting in "Model Settings - > Backend Configuration" as shown below: 

    By default the setting "Return Null on Not Row Found" is not checked, which means that if there is a problem with the database integrity an exception will be thrown. In your case this is not database integrity issue but designed behavior so you can safely switch the option on. 

    I hope this helps. Do not hesitate to contact us again with any further questions. 

    Kaloyan Nikolov
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
Back to Top