Member with identifier 'component_type_name' does not exist in the metadata collection. \ R \ nParameter: identifier

In the database, I have a SERVICE table. For this table, I have triggers after INSER / UPDATE / DELETE. When I try to insert a record into the database using EF, I get the error message "The element with the identifier 'component_type_name' does not exist in the metadata collection. \ R \ nParameter: identifier . The column 'component_type_name" does not exist in the SERVICE table, but in the table COMPONENT_TYPES_IN_SERVICE. This is the insert trigger for the SERVICE table. When I remove the trigger from the table, I have no problem inserting.

CREATE TRIGGER [dbo].[UpdateComponentTypesInServiceOnInsert]
   ON [dbo].[SERVICE] 
   AFTER INSERT
AS 
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @componentID int;
SET @componentID = 0;

DECLARE @ComponentTypeID int;
SET @ComponentTypeID = 0;

DECLARE @ComponentTypeName nvarchar(255);
SET @ComponentTypeName = null;

SELECT @componentID = component_id from inserted;

SELECT @ComponentTypeID = c.component_type_id, @ComponentTypeName = ct.description from COMPONENTS c
inner join dbo.COMPONENT_TYPES ct on c.component_type_id = ct.id
WHERE c.id = @componentID; 

Select * from COMPONENT_TYPES_IN_SERVICE cts
where cts.id = @ComponentTypeID;

IF (@@ROWCOUNT > 0)
    BEGIN
        UPDATE COMPONENT_TYPES_IN_SERVICE
        SET number_of_components = number_of_components + 1
        WHERE id = @ComponentTypeID;
    END
ELSE
    BEGIN
        INSERT INTO COMPONENT_TYPES_IN_SERVICE(id, component_type_name, number_of_components)
        VALUES (@ComponentTypeID, @ComponentTypeName, 1); 
    END
END

Does anyone know any solution ???

+3
source
3

:

Select * from COMPONENT_TYPES_IN_SERVICE cts
where cts.id = @ComponentTypeID;

COMPONENT_TYPES_IN_SERVICE , EF SERVICE, , .

+5

, Entity Framework

+3

The exact cause of this unfamiliar error in most cases is the existence of statements SELECTin triggers when using the Entity Framework. Removing them corrects the error with a high probability.

+1
source

All Articles