Sql server 身份为';组件类型、名称和x27;元数据集合中不存在。\r\n参数名称:标识
在数据库中,我有一个名为SERVICE的表。对于这个表,在INSER/UPDATE/DELETE之后有触发器。尝试使用EF将记录插入数据库时,出现错误“元数据集合中不存在标识为“component\u type\u name”的成员。\r\n参数名称:identity”。服务表中不存在列“component\u type\u name”,但服务中的表component\u TYPES\u中存在列“component\u type\u name”。 这是表服务的插入触发器。当我从表中移除触发器时,插入没有任何问题Sql server 身份为';组件类型、名称和x27;元数据集合中不存在。\r\n参数名称:标识,sql-server,entity-framework,triggers,Sql Server,Entity Framework,Triggers,在数据库中,我有一个名为SERVICE的表。对于这个表,在INSER/UPDATE/DELETE之后有触发器。尝试使用EF将记录插入数据库时,出现错误“元数据集合中不存在标识为“component\u type\u name”的成员。\r\n参数名称:identity”。服务表中不存在列“component\u type\u name”,但服务中的表component\u TYPES\u中存在列“component\u type\u name”。 这是表服务的插入触发器。当我从表中移除触发器时,
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
有人知道任何解决方案吗?您不能这样做:
Select * from COMPONENT_TYPES_IN_SERVICE cts
where cts.id = @ComponentTypeID;
它将服务中的
组件类型服务中,因为它认为您正在传回一些数据库生成的值。在使用实体框架时,触发器中不能有任何返回值的select语句大多数情况下,这种不熟悉错误的原因是使用实体框架时触发器中存在SELECT
语句。删除它们将很有可能修复错误