在數據庫中,我有一個名爲SERVICE的表。對於這個表,我在INSER/UPDATE/DELETE之後有觸發器。當我嘗試使用EF向數據庫中插入記錄時,出現錯誤「元數據集合中不存在標識爲'component_type_name'的成員。\ r \ n參數名稱:標識」。 「component_type_name」列在SERVICE表中不存在,但在表COMPONENT_TYPES_IN_SERVICE中。 這是表SERVICE的插入觸發器。當我從表格中刪除扳機時,我沒有任何插入問題。元數據集合中不存在標識爲'component_type_name'的成員。 r n參數名稱:標識
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
有沒有人知道任何解決方案???