c# - how to use data annotations to convert int ID to string ID -


i using entity framework code first approach , have class string increments id. have following code in sql server me cannot update-database in package manager, if erase class attribute incrementing string. here sql code:

   create table [dbo].[school](    [schoolid] [int] identity(1,1) not null,    emp_id 'emp_' + cast(schoolid nvarchar(10))persisted,    [dayevent] [nvarchar](100) null,    [daynote] [nvarchar](250) null,     constraint [pk_dbo.school] primary key clustered    (    [schoolid] 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 

first, if post code first class give better answer. presumption have have created true way, think missed databasegenerated attribute specifies how database generates values property.

it takes databasegeneratedoption sets pattern used generate values property in database , has identity options marks related property auto-increment column in database.

so in code first school class, add the:

[databasegenerated(databasegeneratedoption.identity)] 

attribute above schoolid property such this:

public class school {     [key]     [databasegenerated(databasegeneratedoption.identity)]     public int schoolid { get; set; }      public string dayevent { get; set; }     public string daynote { get; set; }     // ... } 

good luck! :)


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -