IDENTITY INSERT and LINQ to SQL

后端 未结 6 1334
难免孤独
难免孤独 2020-12-03 08:04

I have a SQL Server database. This database has a table called Item. Item has a property called \"ID\". ID is the primary key on my table. This primary key is an int with a

6条回答
  •  悲哀的现实
    2020-12-03 08:41

    The ID will be zero until you call context.SubmitChanges();. Step through the code and look at the value after SubmitChanges has been invoked. Remember, the DB is actually assigning the ID (assuming that it's a auto-increment key).

    Take a look at this:

    Working with Entity Keys

提交回复
热议问题