Delete all related items - from Telerik OpenAccess ORM

Using Telerik OpenAccess ORM I have 2 objects Userand Investment. More specifically, it Investmentscontains a foreign key for Useras is typical of many relationships. In other words, each User can have several investments, but each Investment can have only one user.

Then I tried using the "Managed" public access feature

enter image description here

This should mean that I can do something like this User.Investments.Clear();and delete all related investments (or at least it works great in many ways), but unfortunately, when I try to do this, I am greeted by the following error.

"Update failed: Telerik.OpenAccess.RT.sql.SQLException: cannot insert a NULL value in the 'UserID" column, the table' CODECorp.dbo.Investment '; the column does not allow zeros. UPDATE cannot. "

Obviously, ORM is trying to remove the association (i.e. the foreign key) from the investee, rather than removing it. I confirmed this by running the SQL profiler and seeing that it works Update, not Delete.

So what am I missing here? Why is it incorrectly trying to remove the association, and not just delete the row as you expected?

+3
source share
1 answer

IsManaged True, , , . , Telerik Data Access ( Telerik OpenAccess ORM) , , NULL.

Delete . :

dbContext.Delete(User.Investments);
dbContext.SaveChanges();

DELETE. Telerik Data Access .

, . .

+4

All Articles