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 6856249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:51:41+00:00 2026-05-27T01:51:41+00:00

I know this question has been asked many times and after going through posts,

  • 0

I know this question has been asked many times and after going through posts, I believe it has something to do with entity name, but I am completely new to data entity model and while trying to do a simple insert of a blog entry with blog details, I encountered this problem.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

Line 365:    public void AddToblogs(blog blog)
Line 366:    {
Line 367:        base.AddObject("myblogs", blog);
Line 368:    }
Line 369:


Source File: C:\Inetpub\int422_113b16\webcontent\App_Code\blogModel.cs    Line: 367

Stack Trace:

[ArgumentException: An item with the same key has already been added.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
   System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +9382923
   System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.LoadRelationshipTypes() +661
   System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.LoadTypesFromAssembly() +17
   System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load() +25
   System.Data.Metadata.Edm.ObjectItemAttributeAssemblyLoader.Load() +4
   System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) +160
   System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors) +166
   System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) +316
   System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection) +84
   System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly) +151
   System.Data.Objects.ObjectContext.AddObject(String entitySetName, Object entity) +211
   blogEntities.AddToblogs(blog blog) in C:\Inetpub\int422_113b16\webcontent\App_Code\blogModel.cs:367
   BlogManager.BlogAdd(String title, String content, String userName) in C:\Inetpub\int422_113b16\webcontent\App_Code\BlogManager.cs:27
   Project_Admin_create_post.post_Click(Object sender, EventArgs e) in C:\Inetpub\int422_113b16\webcontent\Project\Admin\create-post.aspx.cs:25
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

BlogManager.cs

public class BlogManager
{
    private blogEntities _dbEnt = new blogEntities();

    public BlogManager()
    {
    }

    public void BlogAdd(int numId, string title, string content,string userName) 
    {

        blog newPost = new blog();
        newPost.blog_id = 1;
        newPost.blog_title = title;
        newPost.blog_content = content;
        newPost.date_created = null;
        newPost.user_name = userName;

        _dbEnt.AddTotheblog(newPost);
        _dbEnt.SaveChanges();
    }

    public class NameNotUniqueException : Exception
    {
        public NameNotUniqueException(string msg = "INT422 ERROR: matching data already exists")
            : base(msg)
        { }
    }
}

create-post.cs

public partial class Project_Admin_create_post : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            blogStatus.Text = "Your post is published";
            title.Enabled = false;
            content.Enabled = false;
        }
    }

    protected void post_Click(object sender, EventArgs e)
    {
        string _userName = User.Identity.Name;

        BlogManager blogMgr = new BlogManager();
        blogMgr.BlogAdd(title.Text, content.Text, _userName);
    }
}
  • 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-27T01:51:42+00:00Added an answer on May 27, 2026 at 1:51 am

    I think the error message is telling you the truth here. You’ve previously, either in a child object in your blog post, or the blog post itself—added another entity of this type with the same entity key.

    Is it possible that in one of your tables you’ve forgotten to set the identity key for your PK? If so you might have a row with a key of 0, and subsequent inserts are conflicting with it.

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

Sidebar

Related Questions

Yes I know, this question has been asked MANY times but after reading all
I know this question has been asked many times, but my problem is a
I know this question has been asked many times and we have gotten this
I know this question has been asked many times and I've researched it myself
I know this question has been asked many times, but I am having trouble
I know that this question has been asked many times before in different guises
I know this question has been asked many times, but here are my specific
(Using Python 3.1) I know this question has been asked many times for the
Hey all, I know that this question has been asked many times in this
I know this has been a question asked many times and I wish there

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.