1

When I use Entity Framework to insert a row, I get this error:

The member with identity 'AutoNumber' does not exist in the metadata collection.\r\nParameter name: identity

The problem is an insert trigger on the table.

Here's the table structure:

CustomerID | (identity, auto increment)
FirstName  |
LastName   |

Here's the trigger:

CREATE TRIGGER [dbo].[TR_Customer_INSERT] 
ON [dbo].[Customer]
FOR INSERT
AS
    SET NOCOUNT ON

    SELECT @@IDENTITY AS AutoNumber
    RETURN

Is it possible to use Entity Framework without deleting the trigger? Could I define 'AutoNumber' somehow? Why doesn't it just ignore the results of the trigger?

Update: I gave up and deleted the trigger.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
scw
  • 5,450
  • 8
  • 36
  • 49
  • Does that trigger work when you insert a row normally? – Mikeb Sep 25 '13 at 18:55
  • Yes, it's an old trigger and old db structure. I'm able to insert a row if I execute `insert into Customer values('jane','doe')` – scw Sep 25 '13 at 19:03

2 Answers2

1

You cannot do this:

Select * from COMPONENT_TYPES_IN_SERVICE cts

where cts.id = @ComponentTypeID;

It returns COMPONENT_TYPES_IN_SERVICE record back to your application and EF tries to copy returned values into SERVICE because it thinks that you are passing back some database generated values.

The member with identity 'component_type_name' does not exist in the metadata collection.\r\nParameter name: identity

Community
  • 1
  • 1
user1924375
  • 10,581
  • 6
  • 20
  • 27
0

see this reply

Hence, turn off validation in the EF framework:

context.Configuration.ValidateOnSaveEnabled = false 
Community
  • 1
  • 1
pask23
  • 714
  • 11
  • 20