Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

Field 'Id' doesn't have a default value when use InsertAsync or UpdateAsync

Open niannnshaooo opened this issue 7 years ago • 2 comments

[ExplicitKey] is used but get error "Field 'Id' doesn't have a default value" when use InsertAsync or UpdateAsync

niannnshaooo avatar Oct 12 '18 01:10 niannnshaooo

Same problem for me. In my case this issue only appears if a previous Update<T> or Delete<T> is invoked.

I've tracked this issue down to the lines 441 and 505 where the ExplicitKeyProperties are added to the KeyProperties-List.

I think the ExplicitKeyProperties should be rather concated with KeyProperties rather than added. Any thoughts about this?

JollyRoger91 avatar Oct 12 '18 11:10 JollyRoger91

I believe the problem you are is related to a series of open issues related to InsertAsync(), UpdateAsync, and DeleteAsync() corrupting an internal cache of types and their attributes. I have seen various issues that happen intermittently when using the previously mentioned async methods.

I was able to resolve them by switching to the synchronous versions of the methods, which is not ideal because now I have synchronous blocking code running inside of async methods which run on the thread pool -- a recipe for thread starvation.

Here are the issues that appear to be related: https://github.com/StackExchange/Dapper/issues/793 https://github.com/StackExchange/Dapper/issues/1027 https://github.com/StackExchange/Dapper/issues/1076 https://github.com/StackExchange/Dapper/issues/1139

These issues could use some love. I have a hard time recommending using Dapper to friends and coworkers for a new project at this point due to the behavior of these async methods.

kriskalish avatar Jul 10 '19 15:07 kriskalish