Good day,
I've the following code:
Role role; foreach (var department in departments) { role = new Role(); role.Name = department;
em.AddEntity(role); }
em.SaveChanges();
|
Which
used to work fine. But when I cleaned up the db and executed this same
code, I'm now getting the following error when adding the 2nd entity to
AddEntity():
"An entity with this key: Role: 0 already exists in this EntityManager"
The
Id is Primary Key and Identity auto-incremented by 1. But somehow the
Id is not longer auto-incremented when being added to the EntityManager.
This is the data property of the RoleId, generated by DevForce:
[Key] [DataMember] [Bindable(true, BindingDirection.TwoWay)] [Editable(true)] [Display(Name="Id", AutoGenerateField=true)] [IbVal.RequiredValueVerifier( ErrorMessageResourceName="Role_Id")]
|
And the script for the Role table:
CREATE TABLE [dbo].[Role]( [Id] [smallint] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](25) NOT NULL, CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH
(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
|
Could someone be so kind to point me out what is the problem?
Thanks in advance,
Dave