Getting the error “cannot add an entity that already exists.” while inserting a table's value in to DB without procedure

前端 未结 5 1620
谎友^
谎友^ 2021-01-21 05:15

I am inserting a list of records to the DB table with Linq to sql like this:

//my DataContext Class
 using (VTMMedicalDBDataContext objVTMMedicalDBDataContext =          


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 05:53

    I have a primary key but I already made it as AutoGenerated as true in DBML

    That's fine, however, have you made the field auto-generated at database level? AutoGenerated at DBML level won't actually generate any values for you, it just indicates to the model that the value will be generated by the storage provider (so it probably omits sending it as part of the query).

提交回复
热议问题