简体   繁体   中英

How to Specify Identity Column in Linq2SQL

I want to go with Linq2SQL first and get it to create sql db for me but when I was creating fields I realized I couldn't see any Identity feature or something on Properties window.

What should I do? What I am thinking is to create db like this way and then go to SQL DB and change the column to Identity.

Here is the snapshot of the selected UserId column in Linq2SQL file.

Thanks in advance.

在此处输入图片说明

It's set as autogenerated, which is how linq-to-sql columns are normally represented.

Have a look at the generated .cs file and see what it looks like. In a file generated by sqlmetal, an identity column has this attribute:

[global::System.Data.Linq.Mapping.ColumnAttribute(
    Storage="_ID", AutoSync=AutoSync.OnInsert, 
    DbType="Int NOT NULL IDENTITY", 
    IsPrimaryKey=true, IsDbGenerated=true)] 

Can you find anything similar in your file? Specifically it is the DbType that is interesting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM