DapperLib / Dapper.Contrib

Dapper community contributions - additional extensions for Dapper
Other
268 stars 99 forks source link

Internal Table Properties are Ignored #160

Open alamb3142 opened 1 year ago

alamb3142 commented 1 year ago

This wasn't clear from the docs, but these methods don't appear to map internal properties to column names, only the public ones. I got the following error trying to call InsertAsync<T> on an internal model:

Exception thrown: 'System.Data.SqlClient.SqlException' in System.Private.CoreLib.dll: 'Incorrect syntax near ')'.'

It turns out that the property -> column mapping is calling Type.GetProperties(), which returns only public properties by default, which was generating the follow query:

INSERT INTO dbo.my_table () values (); SELECT SCOPE_IDENTITY() id

I've raised #159 to allow these models to be marked as internal without having to override that modifier on all of the table class's properties.