开发者

"An item with the same key has already been added" error when calling Context AddObject

开发者 https://www.devze.com 2023-03-15 21:36 出处:网络
Can somebody please help me with this error. I have an ASP.NET WebApp, within the Entity Model I have an entity called tb_AdminUser, with a UserID property as GUID. This is also the Entity Key. The en

Can somebody please help me with this error. I have an ASP.NET WebApp, within the Entity Model I have an entity called tb_AdminUser, with a UserID property as GUID. This is also the Entity Key. The entity is not in any relationship with any other entity. I get the error when calling the AddObject() function.

In my code I call the following...

    SQL2008R2_824852_leapdbEntities temp = new SQL2008R2_82485开发者_高级运维2_leapdbEntities();

    tb_AdminUser au = new tb_AdminUser();
    au.UserID = Guid.NewGuid();
    au.Username = "TEST";
    au.Password = "pete@webinspired.net";
    au.LockedOut = false;
    au.Surname = "Feehan";
    au.Forename = "Pete";


    temp.tb_AdminUser.AddObject(au); //error occurs here
    temp.SaveChanges();

The EDMX XML Code is as follows

    <EntityType Name="tb_AdminUser">
      <Key>
        <PropertyRef Name="UserID" />
      </Key>
      <Property Name="UserID" Type="uniqueidentifier" Nullable="false" />
      <Property Name="Forename" Type="nvarchar" Nullable="false" MaxLength="50" />
      <Property Name="Surname" Type="nvarchar" Nullable="false" MaxLength="50" />
      <Property Name="Username" Type="nvarchar" Nullable="false" MaxLength="50" />
      <Property Name="Password" Type="nvarchar" Nullable="false" MaxLength="50" />
      <Property Name="LockedOut" Type="bit" Nullable="false" />
    </EntityType>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号