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

Error while Removing an Object

2 Answers 140 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Santhosh
Top achievements
Rank 1
Santhosh asked on 10 Sep 2009, 02:19 PM
Hellow all,

I have a problem while Removing an object in the Scope.

Error Code:

Delete failed: Telerik.OpenAccess.RT.sql.SQLException: The DELETE statement   
conflicted with the REFERENCE constraint "ref_project_tasks_tasks". The conflict   
occurred in database "JumpPMC", table "dbo.project_tasks", column   
'tasks_id'.<BR>The statement has been terminated.<BR>&nbsp;&nbsp; at   
Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate()<BR>&nbsp;&nbsp;   
at   
OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeUpdate()<BR>&nbsp;&nbsp;   
at   
OpenAccessRuntime.Relational.RelationalStorageManager.deleteRow(PreparedStatement   
ps, RelationalOID oid, String sql)<BR>Row: <A   
href="mailto:GenericOID@4">GenericOID@4</A> Tasks tasks_id=1<BR>DELETE FROM   
[tasks] WHERE [tasks_id] = ?<BR>(set event logging to all to see parameter   
values) Telerik.OpenAccess.RT.sql.SQLException: The DELETE statement conflicted   
with the REFERENCE constraint "ref_project_tasks_tasks". The conflict occurred   
in database "JumpPMC", table "dbo.project_tasks", column 'tasks_id'.<BR>The   
statement has been terminated.<BR>&nbsp;&nbsp; at   
Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeUpdate()<BR>&nbsp;&nbsp;   
at   
OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeUpdate()<BR>&nbsp;&nbsp;   
at   
OpenAccessRuntime.Relational.RelationalStorageManager.deleteRow(PreparedStatement   
ps, RelationalOID oid, String sql)<BR> 

i am getting this error when i tried to remove the Task Item from collection.

from th code

            IObjectScope Scope = ObjectScopeProvider1.GetNewObjectScope();
            Scope.Transaction.Begin();
            List<JumpPMC_Library.Tasks> taskses = (from c in Scope.Extent<Tasks>()
                                                   where c.tuid == Id
                                                   select c).ToList();
            Scope.Remove(taskses[0]);
            Scope.Transaction.Commit();


I am using Forward mapping, my classes are
"Project" class:

[Telerik.OpenAccess.Persistent]
    public class Project
    {
        public Project()
        {
            myTasks = new List<Tasks>();
        }
        public Guid puid = Guid.Empty;
        public  string title = string.Empty;
        private string description = string.Empty;
        private IList<Tasks> myTasks;

        public string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }
        public IList<Tasks> MyTasks
        {
            get
            {
                return myTasks;
            }
            set
            {
                myTasks = value;
            }
        }
        public Guid PUid
        {
            get { return puid; }
            set { puid = value; }
        }
    }


and Tasks Class is like:

[Telerik.OpenAccess.Persistent]
    public class Tasks
    {
        public Tasks()
        {
            Assignee = new Resource();
            resource = new Resource();
            duration = 0;
            Edits = new List<TaskEdits>();
        }
        private Project myproject;
        public Guid tuid = Guid.Empty;
        private string name = string.Empty;
        private string description = string.Empty;
        private Resource assignee;
        private Resource resource;
        private DateTime startDate = DateTime.MinValue;
        private int duration;
        private string project_name = string.Empty;
        private IList<TaskEdits> edits = null;
        public string Name
        {
            get
            {
                return name ;
            }
            set
            {
                name = value;
            }
        }
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        public Resource Assignee
        {
            get
            {
                return assignee;
            }
            set
            {
               assignee = value;
            }
        }
        public DateTime StartDate
        {
            get
            {
                return startDate;
            }
            set
            {
                startDate = value;
            }
        }
        public int Duration
        {
            get { return duration; }
            set { duration = value; }
        }
        public Resource Resource
        {
            get { return resource; }
            set { resource = value; }
        }
        public string Project_Name
        {
            get{ return project_name;}
            set { project_name = value;}
        }
        public Guid TUID
        {
            get{ return tuid;}
            set { tuid = value; }
        }
        public IList<TaskEdits> Edits
        {
            get { return edits; }
            set { edits = value; }
        }
        public Project MYProject
        {
            get { return myproject; }
            set { myproject = value; }
        }
    }




2 Answers, 1 is accepted

Sort by
0
Santhosh
Top achievements
Rank 1
answered on 10 Sep 2009, 04:28 PM

Hellow,

After some googling, i found that i need to change the Canscade setting to break the relationships in the database.

look at this article http://ayende.com/Blog/archive/2006/12/02/NHibernateCascadesTheDifferentBetweenAllAlldeleteorphansAndSaveupdate.aspx


How can i set this property using Openaccess - ORM in my project.
0
PetarP
Telerik team
answered on 11 Sep 2009, 08:44 AM
Hello santhosh,

Your problem is indeed caused by not setting the cascading delete properly. Cascading delete means that when you delete a parent object, all its children should be deleted along with the parent. If this is not set , your server will raise an exception because it will attempt to leave child objects with foreign key reference to a deleted object. To set the cascading delete you should take advantage of the Depend attribute. You can find additional information here.

Sincerely yours,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Santhosh
Top achievements
Rank 1
Answers by
Santhosh
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or