Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6362791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:57:15+00:00 2026-05-24T23:57:15+00:00

I am using Dbcontext to provide and ORM for my application, and I defined

  • 0

I am using Dbcontext to provide and ORM for my application, and I defined my entity classes as follow :

    public partial class Article
    {
     public int ArticleID { get; set; }

     //other properties

        [ConcurrencyCheck]
        [Timestamp]
        public byte[] TimeStamp { get; set; } 

     public virtual ICollection<Comment> Comments { get; set; } 
}

 public partial class Comment
    {

        public int CommentID { get; set; }

        //other properties 

        public virtual Article Article { get; set; }

}

And for CRUD Operations I follow what you can read in this tutorial

But when I want to delete an article and its associated comments as follow :

var qry=from c in _articleRepo.GetArticleByID(id).Comments
                        select c;

                foreach (var item in qry)
                {
                    _commentRepo.DeleteComment(item.CommentID);

                    _commentRepo.Save();
                }



                _articleRepo.DeleteArticle(id);

                _articleRepo.Save();

removing comments works good, but when it comes to remove the article, the application throws this exception :

Store update, insert, or delete statement affected an unexpected
number of rows (0). Entities may have been modified or deleted since
entities were loaded. Refresh ObjectStateManager entries.

any one can help me ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:57:16+00:00Added an answer on May 24, 2026 at 11:57 pm

    I think you are Saving your context one to many times…

    Try removing the _commentRepo.Save(); and just Save on _articleRepo.Save();

    Hope this helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I am using DBContext and have two classes whose properties are all virtual. I
Using Entity Framework 4 CTP5 I have a basic model and a basic DbContext
I am using EF4.1, have upgraded my project, generated POCO classes to use DbContext
I have the following class: public class EFRepository<TContext> : IDisposable where TContext : DbContext,
The goal: I'm trying to use the new Entity Framework 4.1 DbContext API (using
I'm using the DbContext and Code First APIs introduced with Entity Framework 4.1. The
Using C#, I need a class called User that has a username, password, active
I am currently working on my own version of membership using Entity Framework 4.0
My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.