Reputation: 1
Well, I have rather odd exception when I try to insert new value. Please, see attached files for further investigation. So, I use:
SQL Server 2012
VS 2012 Update 2
EF6 Alpha 3 Code First
The problem is I'm trying to insert new value into simple table called dbo.Worker2 (see "Worker2 Table" image file) which consists of 2 columns: TableNumber and Name. The TableNumber column is primary key of integer data type (see "Primary Key column properties" image file). I have installed the latest EF6 alpha3 and trying to insert new value (see "VB.NET Code" image file). However, exception is thrown: "Cannot insert NULL the value NULL into column 'TableNumber', table Bonus.dbo.Worker2'; column does not allow nulls. INSERT fails." (see "VS Exception" image file).
Then I have decided to see what T-SQL query EF sends to SQL Server with SQL Server Profiler and was surprised that no TableNumber was sent by EF (see "Profiler Queries" image file).
Is it bug or I have missed something?
Upvotes: 0
Views: 997
Reputation: 446
By the looks of it you need to set your Worker2 Primary Key property as non-database generated.
something like:
<Key, DatabaseGenerated(DatabaseGeneratedOption.None)>
Public Property TableNumber As Integer
Upvotes: 3