Internal Table Properties are Ignored

Open
#160 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
databases

Research direction

Start at the property-to-column mapping used by InsertAsync and inspect the Type.GetProperties() call described in the issue. Reproduce the failure with an internal model and verify that the generated INSERT no longer has empty column and value lists when the model's properties are mapped.

Written by the indexing model from the issue text.

Description

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.

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DapperLib/Dapper.Contrib

All issues in DapperLib/Dapper.Contrib

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.