locked
Zentity: Different versions of stored procedure Core.CreateOrUpdateResourceType RRS feed

  • Question

  • I am in the process of creating a Zentity Data Model Module that extends the core ZDM.  After re-creating the "Zentity" database (as per the Data Modeling Extension Guide Doc) and executing the Zentity.Core.DataModel.Synchronize() method, I was getting an exception for the stored procedure "Core.CreateOrUpdateResourceType".  It seems that the script that is provided in the <install path for Zentity>\Zentity\Scripts\Database.sql creates this stored procedure with one less parameter than the database which is created when using the installer.  The missing parameter is "@ConfigurationXML".  My question is: Which version is correct?  Do I need a different version of the Zentity.Core.DataModel source code or a different version of the database stored procedures?

    Devhead

    Wednesday, February 8, 2012 2:59 PM

Answers

  • The Zentity application is correct. The bug is in the stored procedure. To fix the bug, you need to modify the
    Core.CretaeOrUpdateResourceType stored procedure. Do not remove the 8th parameter which has other dependencies
    as shown in the screen shot. The correct stored procedure is given below.

    USE [Zentity]
    GO
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [Core].[CreateOrUpdateResourceType]
    @Id UNIQUEIDENTIFIER, @DataModelModuleId UNIQUEIDENTIFIER, @BaseTypeId UNIQUEIDENTIFIER, @Name NVARCHAR (100), @Uri NVARCHAR (1024), @Description NVARCHAR (4000), @Discriminator INT, @configXml NVARCHAR (4000)
    AS
    BEGIN
    	IF (SELECT COUNT(1) FROM [Core].[ResourceType] WHERE Id = @Id) = 0
    	BEGIN
    
    		INSERT INTO [Core].[ResourceType]
               ([Id]
               ,[DataModelModuleId]
               ,[BaseTypeId]
               ,[Name]
               ,[Uri]
               ,[Description]
               ,[Discriminator])
    		VALUES
               (@Id
               ,@DataModelModuleId
               ,@BaseTypeId
               ,@Name
               ,@Uri
               ,@Description
               ,@Discriminator);
    	END
    	ELSE
    	BEGIN
    		UPDATE [Core].[ResourceType]
    		   SET [DataModelModuleId] = @DataModelModuleId
    			  ,[BaseTypeId] = @BaseTypeId
    			  ,[Name] = @Name 
    			  ,[Uri] = @Uri
    			  ,[Description] = @Description
    			  ,[Discriminator] = @Discriminator
    		 WHERE [Id] = @Id
    	END
    	
    	-- Update the max discriminator value.
    	DECLARE @MaxDiscriminator [int];
    	DECLARE @ConfigurationExists [bit];
    	SELECT @ConfigurationExists = 1, @MaxDiscriminator = [ConfigValue]
    	FROM [Core].[Configuration]
    	WHERE [ConfigName] = 'MaxDiscriminator';
    
    	IF @ConfigurationExists IS NULL
    	BEGIN
    		INSERT INTO [Core].[Configuration]
    		SELECT 'MaxDiscriminator', 
    		CASE WHEN MAX([Discriminator]) > @Discriminator THEN MAX([Discriminator])
    		ELSE @Discriminator END
    		FROM [Core].[ResourceType];
    	END
    	ELSE
    	BEGIN
    		UPDATE [Core].[Configuration]
    		SET [ConfigValue] = 
    		CASE WHEN CAST([ConfigValue] AS [int]) > @Discriminator THEN [ConfigValue]
    		ELSE @Discriminator END
    		WHERE [ConfigName] = 'MaxDiscriminator';
    	END
    END
    


    • Marked as answer by Gump Thursday, February 9, 2012 3:14 PM
    Thursday, February 9, 2012 12:19 PM