scm0sml
asked on
remove not working with entity framework.
I am using entity framework and have the following:
blog has a list of BlogComments as in blog.BlogComments() and when I try to do the remove I am getting:
The DELETE statement conflicted with the REFERENCE constraint \"FK__BlogComme__BlogI__1D E57479\". The conflict occurred in database \"MyDatabase\", table \"dbo.BlogComments\", column 'BlogID'.\r\nThe statement has been terminated."}
How can I get this delete to cascade
var id = Convert.ToInt32(ddBlogs.SelectedValue);
var blog = (from b in db.Blogs
where b.ID == id
select b).FirstOrDefault();
db.Blogs.Remove(blog);
db.SaveChanges();
blog has a list of BlogComments as in blog.BlogComments() and when I try to do the remove I am getting:
The DELETE statement conflicted with the REFERENCE constraint \"FK__BlogComme__BlogI__1D
How can I get this delete to cascade
This blog row which you are deleting has a reference in some other table. So you to delete them first and delete this blog
ASKER
But cant i get it to do that automatically?
Blog is blogcomments parent, surely i should be able to get this delete to cascade?
Blog is blogcomments parent, surely i should be able to get this delete to cascade?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK great thanks for your link there.
Including the blogcomments in the initial load meant they could be deleted.
As it is a simple application this will work fine but for a larger size app I would have created the cascade rule on the db.
Thanks again.
Including the blogcomments in the initial load meant they could be deleted.
As it is a simple application this will work fine but for a larger size app I would have created the cascade rule on the db.
Thanks again.