This is a migrated thread and some comments may be shown as answers.
NoSuchObjectException and false references
1 Answer 38 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Miika
Top achievements
Rank 1
Miika asked on 23 May 2013, 08:52 AM
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:
C#
SQL Server (v. 10.0.1600)
latest version of Telerik OpenAccess (I think 2013 Q3 SP1?)

Regards,
Miika Langille

1 Answer, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 27 May 2013, 04:15 PM
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. 

Regards,
Kaloyan Nikolov
Telerik
OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
Tags
LINQ (LINQ specific questions)
Asked by
Miika
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or