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

System.Exception: 'One of your column have a destination mapped more than once. See the inner exception for details.' #118

Closed RockClimbingRocks closed 1 year ago

RockClimbingRocks commented 1 year ago

Description

I'm preforming a bulkUpdate on some data base, where i have 2 different tables with same column names. When i try to update each table at a time, it updates the first one without a problem, and then for the second table i get an error:

System.Exception: 'One of your column have a destination mapped more than once. See the inner exception for details.'

I call the following code for previously mentioned tables

`DapperPlusManager.Entity("UpdateSourceTradeIdAndPositionId_Sb") .Table(table) .Map(x => x.C_SourceTradeId, "SourceTradeId") .Map(x => x.C_PositionId, "PositionId") .Key(x => x.C_ID);

_connection.BulkUpdate("UpdateSourceTradeIdAndPositionId_Sb", updatedPeriods);`

JonathanMagnan commented 1 year ago

Hello @RokPi ,

Do you think you could create a runnable project with the issue? It doesn’t need to be your project, just a new solution with the minimum code to reproduce the issue.

Best Regards,

Jon

RockClimbingRocks commented 1 year ago

i coud not create a runnable proect with that issue, but i could shorten it for u, it would be something like this:

namespace WebApplication1.Controllers
{

    [Route("api/[controller]")]
    [ApiController]
    public class SyncAllegroIdsController : ControllerBase
    {

        public void UpdateTabble(List list, string table)
        {
            // CREATE mapping only once
            DapperPlusManager.Entity<MyObject>("UpdateSourceId_Sb").Table(table)
                                                                   .Map(x => x.C_SourceId, "SourceId")
                                                                   .Key(x => x.C_ID);

            // UPDATE only the name by using the mapping previously created for this case
            connection.BulkUpdate("UpdateSourceId_Sb", updatedPeriods);
        }

        [HttpPost]
        [Route("[action]")]
        public void SyncSourceTradeId()
        {
            // List1 and List2 are some rand

            CorrectIds_SB(list1, "dbo.Table1");
            CorrectIds_SB(list2, "dbo.Table2");

            }
        }
    }
}
JonathanMagnan commented 1 year ago

Hello @RokPi ,

Unfortunately, we will need a project as this is currently impossible for us to re-create this issue (We can easily, but we will simply duplicate a column by purpose via data annotation so that will not be really helpful).

If you wish, you can you can send your full project in private here: info@zzzprojects.com

The project doesn't have to compile (so you can remove a lot of file). Just make sure that all files really required by us to investigate why it could happen are still there.

Best Regards,

Jon

JonathanMagnan commented 1 year ago

Hello @RokPi,

Since our last conversation, we haven't heard from you.

As mentioned in my last message, we would need a project to be able to help you.

Let me know if you need further assistance.

Best regards,

Jon

JonathanMagnan commented 1 year ago

Hello @RokPi ,

A simple reminder that we are here to assist you.

Don't hesitate to contact us if you need more information.

Best regards,

Jon

csseba commented 1 year ago

Hi, Having exactly the same error here. Two different tables have a foreign key called for example order_id.

When trying to perform a bulk merge in the second table, inside the same transaction, I get the following error:

The following destination column is mapped more than once: 'order_id'

JonathanMagnan commented 1 year ago

Hello @csseba ,

Do you think you could provide us a project as already asked for this issue?

It will be way easier for us to try to fix an issue that we can already reproduce through a project than trying to spend time again to try to reproduce it.

Best Regards,

Jon

csseba commented 1 year ago

Hi @JonathanMagnan, The problem was on my side, I was mapping the columns in a public constructor, which means the mapping was happening more than once, just changed the constructor to a static one, and seems to be all right now.

Thank you

pawannogariya commented 10 months ago

I am facing the same issue. I have the base class for all the entities classes in which I have "id" column. Whenever I try to update the table it complains me with this error

The following destination column is mapped more than once: 'id'

I am mapping column names with the table columns attribute for all my entities like this

var entityBaseType = typeof(EditableEntityBase<int>);
var entityTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t != entityBaseType && entityBaseType.IsAssignableFrom(t));

foreach (var entityType in entityTypes)
{
    SqlMapper.SetTypeMap(entityType, new CustomPropertyTypeMap(
      entityType, (type, columnName) => type.GetProperties().FirstOrDefault(prop =>
      prop.GetCustomAttributes(false).OfType<ColumnAttribute>().Any(attr => attr.Name == columnName))));
}

I have tried everything but nothing is working. It is not at all doing the bulk update.

JonathanMagnan commented 10 months ago

Hello @pawannogariya ,

Do you think you could provide us a project with this issue? It will be easier for us to find out the real reason of why it's happening in your case. You can send your project in private here if needed: info@zzzprojects.com

Best Regards,

Jon