This is a migrated thread and some comments may be shown as answers.

How to use string property as ID

1 Answer 64 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paresh
Top achievements
Rank 1
Paresh asked on 28 Aug 2014, 12:21 AM
Hi,

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'

Thanks,
Paresh

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 28 Aug 2014, 08:39 PM
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.

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.
 
Tags
Development (API, general questions)
Asked by
Paresh
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or