Error while Removing an Object

Thread is closed for posting
3 posts, 0 answers
  1. Santhosh
    Santhosh avatar
    28 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2009 Link to this post

    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. Santhosh
    Santhosh avatar
    28 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2009 Link to this post


    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.
  3. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 11 Sep 2009 Link to this post

    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.
Back to Top