Discriminator column other than 'voa_class'

8 posts, 0 answers
  1. Igor
    Igor avatar
    13 posts
    Member since:
    Jul 2011

    Posted 07 Jul 2011 Link to this post

    I try to apply OpenAccessc with our databases with which we work through other manufacturer ORM .
    New components (using OpenAccess) should work in parallel with written earlier.
    Thus I cannot change the database scheme.
    The vertical model for inheritance realisation is used. Old databases use uniqueidentifier column ' ClassUID ' (older databases - integer ClassID) as discriminator.
    There and then there was a question.
     How to specify that for discriminator it is necessary to use a field with a name ' ClassUID ' (' ClassID ') instead of ' voa_class '?
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 07 Jul 2011 Link to this post

    Hello Igor,

     You can easily do that in the Mappings Details Editor. As you can see you have a dropdown with all of the table's columsn from which you can choose the one of your liking. This is of course if you are using our visual designer.

    If you are using the Fluent Mapping API you can have a look at this help article

    I hope this proves to be helpful, however if you have further questions please do not hesitate to ask.

    Regards,
    Serge
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
  3. DevCraft banner
  4. Igor
    Igor avatar
    13 posts
    Member since:
    Jul 2011

    Posted 08 Jul 2011 Link to this post

    Thanks for the answer.
    I want to receive representation about "compatibility" of use OpenAccess with ours "ORM-aware" databases before going deep.
    After several attempts I have received wished for the discriminator with type Int32.
    In xml it is simple

            <orm:discriminator discriminator-value = "6">
              <orm:column name = "ClassID" sql-type = "int" nullable = "true" length = "0" scale = "0" ado-type = "Int32"/>
            </orm:discriminator>

    Designer the good thing but often hides a picture. Fluent Mapping API seems to useful for small class set.
    It is a pity that the documentation section about .rlinq file format is not full and the formal scheme is not defined in the editor (xmlns:orm="http://tempuri.org/ORM").

    As I wrote our current databases use Guid in domain schema in (with MS SQL - uniqueidentifier and Oracle - varchar (36) at backend) as the discriminator.
    When I have tried to work with MS SQL I have received GuidConverter error.

            <orm:discriminator discriminator-value = "{C83D9A0F-5E6F-4860-8BA8-FB30AB9106E2}">
              <orm:column name = "ClassUID" sql-type = "uniqueidentifier" nullable = "true" length = "0" scale = "0" ado-type = "Guid"/>
            </orm:discriminator>

    I have specified Guid string in a format the perceived constructor of type CLR Guid. Same form implicitly converted by MS SQL in type uniqueidentifier.

    I have tried to change type in domain model to  String, but it too has led to an exception in GuidConverter.

    It probably to force to work? What format of a line should be used or it is possible to set Converter?
    Please point me.
  5. Serge
    Admin
    Serge avatar
    375 posts

    Posted 13 Jul 2011 Link to this post

    Hi Igor,

     So lets recap you have added a new model that and retrieved the schema information from a table that has a discriminator column that is of type uniqueidentifier. Now you have a guid field, that you cannot use as a discriminator and if you change the member type to string you get a converter exception. 

    I am having a bit of trouble reproducing your exact problem, could you please send me either your whole project or just the rlinq file and the database schema. 

    Please note that we published the Q2 release today, I suggest you grab it as it contains many fixes and improvement to OpenAccess and the first release of the OpenAccess Profiler.

    I am looking forward to resolving this issue with you.

    Regards,
    Serge
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
  6. Igor
    Igor avatar
    13 posts
    Member since:
    Jul 2011

    Posted 27 Jul 2011 Link to this post

    Ok. I Use 2011 Q2 713
    I attach sample project with rar extension. I add two type of discriminators : string(36) and guid.
    Actually i need guid for ours databases.

    1 with GUID discriminator a have :

    Telerik.OpenAccess.Exceptions.MetadataException was unhandled
      Message=The db-class-id column of class 'ConsoleApplication1.BaseClass1' could not be created: Type converter initialization failed. The converter with name 'GuidConverter' does not convert from CLR type 'System.String' to SQL type 'uniqueidentifier'.
    Parameter name: converterName
    Actual vale is OpenAccessRuntime.Data.GuidConverter, Telerik.OpenAccess.Runtime, Version=2011.2.713.2, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342.
      Source=Telerik.OpenAccess
      CanRetry=true
      AmbiguousValue=Type converter initialization failed. The converter with name 'GuidConverter' does not convert from CLR type 'System.String' to SQL type 'uniqueidentifier'.
    Имя параметра: converterName
    Actual vale is OpenAccessRuntime.Data.GuidConverter, Telerik.OpenAccess.Runtime, Version=2011.2.713.2, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342.
      ClassName=ConsoleApplication1.BaseClass1
      Column=0
      Context=--> EntitiesModel/namespace[ConsoleApplication1]/class[BaseClass1]/db-class-id="9739eb20-6836-4ebb-930f-bb2c48f848cb"
      ErrorId=0
      IsWarning=false
      Line=0
      StackTrace:
           в Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
           в Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
           в OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL()
           в OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createStorageManagerFactory()
           в OpenAccessRuntime.DataObjects.PersistenceManagerFactoryImp.createStorageManagerFactory()
           в OpenAccessRuntime.DataObjects.PersistenceManagerFactoryBase.init()
           в OpenAccessRuntime.DataObjects.PersistenceManagerFactoryImp.init()
           в OpenAccessRuntime.DataObjects.BootstrapPMF.getPersistenceManagerFactory(PropertySet props)
           в Telerik.OpenAccess.RT.Helper.getPersistenceManagerFactory(PropertySet props)
           в Telerik.OpenAccess.RT.DatabaseAdapter.AssertPersistenceManagerFactory(String usr, String password, Boolean open)
           в Telerik.OpenAccess.RT.DatabaseAdapter.GetObjectScope(TransactionProvider provider)
           в Telerik.OpenAccess.Database.GetObjectScope(TransactionProvider provider)
           в Telerik.OpenAccess.OpenAccessContextBase.GetScope()
           в Telerik.OpenAccess.OpenAccessContext.GetAll[T]()
           в ConsoleApplication1.EntitiesModel.get_BaseClass1() в D:\Development\svn.training\Telerik\OpenAccessTests\ConsoleApplication1\ConsoleApplication1-1\EntityDiagrams1.cs:строка 55
           в ConsoleApplication1.Program.Main(String[] args) в D:\Development\svn.training\Telerik\OpenAccessTests\ConsoleApplication1\ConsoleApplication1-1\Program.cs:строка 18
           в System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           в System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           в System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           в System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.ArgumentOutOfRangeException
           Message=Type converter initialization failed. The converter with name 'GuidConverter' does not convert from CLR type 'System.String' to SQL type 'uniqueidentifier'.
    Имя параметра: converterName
    Actual vale is OpenAccessRuntime.Data.GuidConverter, Telerik.OpenAccess.Runtime, Version=2011.2.713.2, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342.
           Source=Telerik.OpenAccess.Runtime
           ParamName=converterName
           StackTrace:
                в OpenAccessRuntime.Relational.metadata.RelationalMappingResolver.CreateConverter(TypeConverterName converterName, RelationalColumn col, String originalType, Boolean secondary)
                в OpenAccessRuntime.Relational.metadata.RelationalColumn..ctor(RelationalJavaTypeMapping m, RelationalTypeRegistry relationalTypeRegistry, String oType, Boolean secondary)
                в OpenAccessRuntime.Relational.RelationalMetaDataBuilder.processClassIdCol(ClassMetaData cmd, Boolean quietParam, Hashtable classIdMap)
           InnerException:


    2 with string discriminator work ok.
    I think it's is not nesessery add discriminator column

    If you type e-mail i send all project.
    rlink and sql script below
    --------------------
    <?xml version="1.0" encoding="utf-8"?>
    <DomainModel xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="2.0.0.0" name="EntitiesModel" namespace="ConsoleApplication1" showPropertiesCompartment="true" xmlns="http://www.telerik.com/ORM">
      <orm:orm name="EntitiesModel" backend="mssql" xmlns:orm="http://tempuri.org/ORM">
        <orm:namespace name="ConsoleApplication1" default="true">
          <orm:class name="BaseClass1" update-schema="true" behavior="readwrite" uniqueId="9e1e835c-6cae-4b9e-a5c2-5ed3297cfa89">
            <orm:table name="BaseClass1" />
            <orm:identity>
              <orm:key-generator name="guid" />
              <orm:single-field field-name="_id" />
            </orm:identity>
            <orm:discriminator discriminator-value="9739eb20-6836-4ebb-930f-bb2c48f848cb">
              <orm:column name="ClassUID" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" ado-type="Guid" />
            </orm:discriminator>
            <orm:field name="_id" property="Id" behavior="readwrite" uniqueId="a71f7431-a9d3-4f9e-b475-c0521a170341" type="System.Guid">
              <orm:column name="Id" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" primary-key="true" ado-type="Guid" />
            </orm:field>
            <orm:field name="_name" property="Name" behavior="readwrite" uniqueId="ea745cff-8530-48e1-a09f-18a00b10ca7b" type="System.String">
              <orm:column name="Name" sql-type="varchar" nullable="false" length="256" scale="0" ado-type="Varchar" />
            </orm:field>
            <orm:field name="_classUID" property="ClassUID" behavior="readwrite" uniqueId="d17fb133-d6a4-4188-8984-63b141900c54" type="System.Guid">
              <orm:column name="ClassUID" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" ado-type="Guid" />
            </orm:field>
            <orm:field name="_classSID" property="ClassSID" behavior="readwrite" uniqueId="2ac4ce61-83f8-474f-979c-e8004bb3a932" type="System.String">
              <orm:column name="ClassSID" sql-type="varchar" nullable="false" length="36" scale="0" ado-type="" />
            </orm:field>
          </orm:class>
          <orm:class name="VerticalClass1" update-schema="true" behavior="readwrite" uniqueId="a0f14193-4397-41d9-bc24-113f129223a1" persistent-baseclass="ConsoleApplication1.BaseClass1" inheritance="new-table">
            <orm:table name="VerticalClass1" />
            <orm:discriminator discriminator-value="6b9f349d-e8f1-4a74-b85d-d7ff6ce43228" />
            <orm:field name="_id" property="Id" behavior="readwrite" uniqueId="b818894f-ca94-44a2-9dcd-51bbdaa9ee54" type="System.Guid">
              <orm:column name="Id" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" primary-key="true" ado-type="Guid" />
            </orm:field>
          </orm:class>
        </orm:namespace>
        <orm:schema schema="">
          <orm:table name="BaseClass1">
            <orm:column name="Id" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" primary-key="true" ado-type="Guid" />
            <orm:column name="Name" sql-type="varchar" nullable="false" length="256" scale="0" ado-type="Varchar" />
            <orm:column name="ClassUID" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" ado-type="Guid" />
            <orm:column name="ClassSID" sql-type="varchar" nullable="false" length="36" scale="0" ado-type="" />
          </orm:table>
          <orm:table name="VerticalClass1">
            <orm:column name="Id" sql-type="uniqueidentifier" nullable="false" length="0" scale="0" primary-key="true" ado-type="Guid" />
          </orm:table>
        </orm:schema>
      </orm:orm>
      <ModelSettings xmlns="">
        <AppConfigConnectionPropertyName>DatabaseConnection</AppConfigConnectionPropertyName>
        <AppConfigConnectionString>Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Development\svn.training\Telerik\OpenAccessTests\ConsoleApplication1\ConsoleApplication1-1\Data\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True</AppConfigConnectionString>
        <InitialCatalog>Database</InitialCatalog>
        <NamingSettings>
          <ClassRules>
            <CaseMode>PascalCase</CaseMode>
            <PluralizationMode>Singularize</PluralizationMode>
          </ClassRules>
          <FieldRules>
            <AddPrefix>_</AddPrefix>
            <CaseMode>CamelCase</CaseMode>
          </FieldRules>
          <PropertyRules>
            <CaseMode>PascalCase</CaseMode>
          </PropertyRules>
        </NamingSettings>
        <CodeGenerationSettings>
          <MappingDefinitionType>Xml</MappingDefinitionType>
          <GenerateMultipleFiles>false</GenerateMultipleFiles>
        </CodeGenerationSettings>
        <SchemaUpdateSettings>
          <DeploymentProject>ConsoleApplication1-1</DeploymentProject>
          <DeploymentDirectory>D:\Development\svn.training\Telerik\OpenAccessTests\ConsoleApplication1\ConsoleApplication1-1</DeploymentDirectory>
          <UpdateDatabaseOperation>Migrate</UpdateDatabaseOperation>
        </SchemaUpdateSettings>
        <BackendConfigurationSettings>
          <BackendConfiguration>
            <Backend>mssql</Backend>
            <ProviderName>System.Data.SqlClient</ProviderName>
            <Logging>
              <LogLevel>All</LogLevel>
            </Logging>
          </BackendConfiguration>
        </BackendConfigurationSettings>
      </ModelSettings>
      <Types>
        <DomainClass Id="9e1e835c-6cae-4b9e-a5c2-5ed3297cfa89" name="BaseClass1" showPropertiesCompartment="true" identityMechanism="Guid" showNavigationCompartment="true" showImplementationCompartment="true">
          <Property Id="a71f7431-a9d3-4f9e-b475-c0521a170341" name="Id" type="Guid" label="Id : Guid" identity="true" />
          <Property Id="ea745cff-8530-48e1-a09f-18a00b10ca7b" name="Name" label="Name : String" />
          <Property Id="d17fb133-d6a4-4188-8984-63b141900c54" name="ClassUID" type="Guid" label="ClassUID : Guid" />
          <Property Id="2ac4ce61-83f8-474f-979c-e8004bb3a932" name="ClassSID" label="ClassSID : String" kind="Persistent" fieldName="_classSID" />
          <inheritors>
            <inheritance Id="29b3553d-7511-4280-b898-f70b13ffff58">
              <DomainClassMoniker name="/EntitiesModel/VerticalClass1" />
            </inheritance>
          </inheritors>
        </DomainClass>
        <DomainClass Id="a0f14193-4397-41d9-bc24-113f129223a1" name="VerticalClass1" showPropertiesCompartment="true" identityMechanism="Guid" showNavigationCompartment="true" showImplementationCompartment="true">
          <Property Id="b818894f-ca94-44a2-9dcd-51bbdaa9ee54" name="Id" type="Guid" label="Id : Guid" identity="true" />
        </DomainClass>
      </Types>
      <domainContext>
        <domainModelHasDomainContext Id="d7cb1764-482e-4351-8716-d3c51efcc8db">
          <domainContainer name="EntitiesModel" namespace="ConsoleApplication1" showPropertiesCompartment="true">
            <entitySetProperty name="BaseClass1" type="BaseClass1" label="BaseClass1 : IQueryable&lt;BaseClass1&gt;" />
            <entitySetProperty name="VerticalClass1" type="VerticalClass1" label="VerticalClass1 : IQueryable&lt;VerticalClass1&gt;" />
          </domainContainer>
        </domainModelHasDomainContext>
      </domainContext>
    </DomainModel>

    ------------------
    /****** Object:  Table [dbo].[VerticalClass1]    Script Date: 07/27/2011 12:05:25 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[VerticalClass1](
        [Id] [uniqueidentifier] NOT NULL,
     CONSTRAINT [pk_VerticalClass1] PRIMARY KEY CLUSTERED
    (
        [Id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    INSERT [dbo].[VerticalClass1] ([Id]) VALUES (N'dcf8493a-9bbf-4f79-ad12-a10357578522')
    INSERT [dbo].[VerticalClass1] ([Id]) VALUES (N'19cc5a1f-88d3-4173-a66a-ccda23d5c587')
    /****** Object:  Table [dbo].[BaseClass1]    Script Date: 07/27/2011 12:05:25 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[BaseClass1](
        [Name] [varchar](256) NOT NULL,
        [Id] [uniqueidentifier] NOT NULL,
        [ClassUID] [uniqueidentifier] NOT NULL,
        [ClassSID] [varchar](36) NOT NULL,
     CONSTRAINT [pk_BaseClass1] PRIMARY KEY CLUSTERED
    (
        [Id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    INSERT [dbo].[BaseClass1] ([Name], [Id], [ClassUID], [ClassSID]) VALUES (N'BaseClass1 Row 1', N'1b6db372-1a9d-4432-af60-80c7e0914a2a', N'9739eb20-6836-4ebb-930f-bb2c48f848cb', N'9739eb20-6836-4ebb-930f-bb2c48f848cb')
    INSERT [dbo].[BaseClass1] ([Name], [Id], [ClassUID], [ClassSID]) VALUES (N'BaseClass1 Row 3', N'1278e44b-1ec9-4e67-9af7-8ce24207e04a', N'9739eb20-6836-4ebb-930f-bb2c48f848cb', N'9739eb20-6836-4ebb-930f-bb2c48f848cb')
    INSERT [dbo].[BaseClass1] ([Name], [Id], [ClassUID], [ClassSID]) VALUES (N'VerticalClass1 Row 1', N'dcf8493a-9bbf-4f79-ad12-a10357578522', N'6b9f349d-e8f1-4a74-b85d-d7ff6ce43228', N'6b9f349d-e8f1-4a74-b85d-d7ff6ce43228')
    INSERT [dbo].[BaseClass1] ([Name], [Id], [ClassUID], [ClassSID]) VALUES (N'VerticalClass1 Row 2', N'19cc5a1f-88d3-4173-a66a-ccda23d5c587', N'6b9f349d-e8f1-4a74-b85d-d7ff6ce43228', N'6b9f349d-e8f1-4a74-b85d-d7ff6ce43228')
    /****** Object:  Default [DF_BaseClass1_ClassSID]    Script Date: 07/27/2011 12:05:25 ******/
    ALTER TABLE [dbo].[BaseClass1] ADD  CONSTRAINT [DF_BaseClass1_ClassSID]  DEFAULT ('xxxxxxxxx') FOR [ClassSID]
    GO


  7. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 28 Jul 2011 Link to this post

    Hi Igor,

    Thank you for the clarification. I am afraid that at the moment only int and string columns can be used as a discriminator, so the exception you are getting is actually expected. The ability to use a guid column as discriminator is not yet implemented but is on our TODO list. However, at this stage I am not able to give you a time-frame when it will be implemented.
    Please excuse us for the inconvenience caused.

    Regards,
    Alexander
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
  8. David
    David avatar
    11 posts
    Member since:
    Jun 2014

    Posted 15 Jul 2014 in reply to Alexander Link to this post

    Is this still the case in 2014? I appear to be getting the same error.

    Error 1 The db-class-id column of class 'RTSDataModel.Phone' could not be created: Type converter initialization failed. The converter with name 'OpenAccessRuntime.Data.GuidConverter' does not convert from CLR type 'System.String' to SQL type 'uniqueidentifier'.
    Parameter name: converterName
    Actual value was OpenAccessRuntime.Data.GuidConverter. 
  9. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 17 Jul 2014 Link to this post

    Hi David,

    Unfortunately you have bumped against a limitation in Telerik Data Access. The GUID is not supported type for discriminator column, and this is the reason for the validation error. The supported types are Int or String. To bypass the error you should change the discriminator column type to one of the listed.

    I hope that helps.

    Regards,
    Boris Georgiev
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner