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

foreign key constaints problems

2 Answers 77 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MATEUSZ
Top achievements
Rank 1
MATEUSZ asked on 26 May 2013, 12:35 PM
Hi, I use Telerik-OpenAccess-ORM-2012.2.924.1 and have got problems with fluent mapping @sqlite backend.

Foreign key constaints are generated properly, model.DefaultMapping.NullForeignKey = true;

First problem is the same as described here: http://www.telerik.com/community/forums/orm/general-discussions/nosuchobjectexception-with-non-nullable-foreign-keys.aspx

Another one: I have entities:
Trainer{}
Course{Trainer}
I created trainer and course with the trainer assigned, then removed thrainer and it succeeded - no exception was thrown. Obviously, when I opened CourseEditView, everything crashed due to "no such row for id".

Are these issues known for this version?

Thanks

2 Answers, 1 is accepted

Sort by
0
MATEUSZ
Top achievements
Rank 1
answered on 26 May 2013, 01:52 PM
I can't reproduce first cas in unit test, because it's strongly connected with wpf databinding. However, I can post part of output:

A first chance exception of type 'Telerik.OpenAccess.Exceptions.NoSuchObjectException' occurred in Telerik.OpenAccess.dll
A first chance exception of type 'Telerik.OpenAccess.Exceptions.NoSuchObjectException' occurred in Telerik.OpenAccess.dll
A first chance exception of type 'Telerik.OpenAccess.Exceptions.NoSuchObjectException' occurred in Telerik.OpenAccess.dll
A first chance exception of type 'Telerik.OpenAccess.Exceptions.NoSuchObjectException' occurred in Telerik.OpenAccess.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=DetailsObject.MainTrainer; DataItem='CourseDetailsViewModel' (HashCode=25661650); target element is 'RadComboBox' (Name=''); target property is 'SelectedItem' (type 'Object') NoSuchObjectException:'Telerik.OpenAccess.Exceptions.NoSuchObjectException: No row for Asyc.Scheduler.Core.DomainObjects.Trainer ('Trainers') GenericOID@fffff438 Trainer Id=0
   at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
   at OpenAccessRuntime.ExceptionWrapper.Throw()
   at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x, Boolean needsRollback)
   at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.getObjectByIdForState(OID oid, Int32 stateFieldNo, Int32 navClassIndex, OID fromOID)
   at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.getObjectByIdForState(OID oid, Int32 stateFieldNo, Int32 navClassIndex, OID fromOID)
   at OpenAccessRuntime.common.GenericState.getObjectField(Int32 stateFieldNo, PersistenceCapable owningPC, OpenAccessPMProxy pm, OID oid)
   at OpenAccessRuntime.DataObjects.PCStateMan.SetObjectField(PersistenceCapable _pc, Int32 field, Object currentValue, Object newValue)
   at Asyc.Scheduler.Core.DomainObjects.Course.OpenAccessEnhancedSet<MainTrainer>k__BackingField(Course owner, Trainer value)
   at Asyc.Scheduler.Core.DomainObjects.Course.<set_MainTrainer>(Trainer value)
   at Asyc.Scheduler.Core.DomainObjects.Course.<MainTrainer>c__Binding.SetValue(Object& instance, Arguments index, Trainer value, Object aspectArgs) in :line 0
   at PostSharp.Aspects.Internals.LocationInterceptionArgsImpl`1.ProceedSetValue()
   at Asyc.Core.Notification.NotifyPropertyChangedAttribute.OnPropertySet(LocationInterceptionArgs args) in D:\work\scheduler\asyc_core_ext\Asyc.Core\Notification\NotifyPropertyChangedAttribute.cs:line 44
   at Asyc.Scheduler.Core.DomainObjects.Course.set_MainTrainer(Trainer value) in :line 0'

I'm using AOP, but it has nothing to do with the problem.

However, I can show test for second case:
[Test]
        public void throws_when_trying_to_remove_referenced_object()
        {
            var trainer = new Trainer();
            DataService.Insert(trainer);
            DataService.Commit();
 
            var course = new Course() {MainTrainer = trainer};
            DataService.Insert(course);
            DataService.Commit();
 
            DataService.Remove(trainer);
            Assert.Throws<Exception>(() => DataService.Commit());
        }

Afaik, it should have produced exception? If true, it does not.
0
Boris Georgiev
Telerik team
answered on 29 May 2013, 03:44 PM
Hi Mateusz,

There aren't any known issues for your first problem. The problem might be in the WPF. Are you using any WPF controls and what is their version? 

In order for us to understand the second issue and assist you in the best possible way, could you please provide us some more information:
1) What are you using for AOP and how is structured your solution? OpenAccess uses OpenAccessEnhancer and if one project is enhanced twice there are known issues.
2) In the unit test code sample there is an object "DataService", what is the type of this object? Is it wrapper of OpenAccessContext or is it an actual Web Service?
3) In your first post, assuming that the relationship is One-to-Many, as I understood the described scenario is:
- Add Trainer
- Add Customer(Trainer)
- Remove Trainer
- Crash when access the customer

In the unit test code sample, the scenario is:
- Add Trainer
- Add Customer(Trainer)
- Crash when removing the trainer. 

There are differences between the first and second scenario. In the second one the exception is expected, because there is a Foreign Key in the database which is pointing to this entity.

Apart from clarifying those points, providing a small sample demonstrating the problem will be of great help to understand the whole picture.

We are looking forward to your feedback.
 
Regards,
Boris Georgiev
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
Development (API, general questions)
Asked by
MATEUSZ
Top achievements
Rank 1
Answers by
MATEUSZ
Top achievements
Rank 1
Boris Georgiev
Telerik team
Share this question
or