zzzprojects / Dapper-Plus

Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
https://dapper-plus.net/
380 stars 84 forks source link

Can't find column in composite key #104

Closed lucasgmagalhaes closed 2 years ago

lucasgmagalhaes commented 2 years ago

image

When I try to map an entity with composite keys that references to columns in database with snake case naming this error is thrown:

An error occured while resolving mapping by name. See the inner exception for details
    ---- System.Exception : Missing Column : UnbId
    On entity : ProgramExecution
    On Table : "program_executions"

I'm trying to do a bulkMerge:

context.BulkMerge(toUpsert);
JonathanMagnan commented 2 years ago

Hello @lucasgmagalhaes ,

The issue is that the Map only map the property to the column you specified.

However, the key method doesn't use the column name you specified in the Map property. So you need to map it again to the right column name

mapper.Key(x => x.UnbId, "unb_id")
      .Key(x => x.GeoId, "geo_id")
      .Key(x => x.ProgramCode, "programe_code")
      .Key(x => x.ReferenceDate, "reference_date")
      .Key(x => x.Start, "start")
      .Key(x => x.End, "end")

We will check on our side how we could force the key to use either name you specified in the Map method (such adding a boolean since we need to say backward compatible) or adding a new method that will be specified for this.

Best Regards,

Jon

JonathanMagnan commented 2 years ago

Hello @lucasgmagalhaes ,

Did you try our alternative solution using multiple key methods?

After some discussion, I do not think we will do anything with the Map method.