-->

asp.net mvc linq sql problem

2019-07-07 02:42发布

问题:

I am working on a project using asp.net mvc 2 and linq to sql. The problem occurs when trying to insert data into a table where the table has an identity column type of tinyint. When trying to insert the following error occurs:

The primary key column of type 'TinyInt' cannot be generated by the server.

Does linq to sql support tinyint datatype?

Please help me

回答1:

From what I have been able to gather, Linq To Sql doesn't support TinyInt for auto increment fields.

Can you change the datatype to smallint or int?

See the following thread on Microsoft Connect:

When you have a table with an identity field of tinyint and it's set to auto increment, you can't add a new record to that table. LINQ says, 'The primary key column of type 'TinyInt' cannot be generated by the server'

Thank you for taking the time to send this feedback and bug report. We have reviewed the issue and confirmed the behavior, but we will not be fixing this in the next release of LINQ to SQL.