How to use string property as ID

2 posts, 0 answers
  1. Paresh
    Paresh avatar
    13 posts
    Member since:
    Jul 2014

    Posted 27 Aug 2014 Link to this post


    I want to define one of the string property in my class as ID (application generated).
    I tried following 
    configuration.HasProperty(x => x.Name).IsIdentity(KeyGenerator.Default).ToColumn("astCode").HasColumnType("nvarchar");

    But it generates following error

    The type 'Telerik.OpenAccess.Metadata.Fluent.StringPropertyConfiguration' cannot be used as type parameter 'TConfiguration' in the generic type or method 'Telerik.OpenAccess.Metadata.Fluent.FluentIdentityConfigurationExtensions.IsIdentity<TConfiguration>(TConfiguration, Telerik.OpenAccess.Metadata.KeyGenerator)'. There is no implicit reference conversion from 'Telerik.OpenAccess.Metadata.Fluent.StringPropertyConfiguration' to 'Telerik.OpenAccess.Metadata.Fluent.IIdentityKeyGenConfiguration'

  2. Boris Georgiev
    Boris Georgiev avatar
    190 posts

    Posted 28 Aug 2014 Link to this post

    Hello Paresh,

    If you want to have string property(varchar column) as a Primary Key, you should not pass KeyGenerator parameter in the IsIdentity() method. The KeyGenerator enum should be used, if you have GUID or int column and you want to have KeyGenerator - Autoinc, IncrementalGuil and to not specify manually the key. But for varchar columns there isn't any KeyGenerator, so you should manually set the PrimaryKey value. In conclusion in your case the fluent definition for the property should look like:
    configuration.HasProperty(x => x.Name).IsIdentity().ToColumn("astCode").HasColumnType("nvarchar");

    I hope that helps.

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