Dapper-Plus icon indicating copy to clipboard operation
Dapper-Plus copied to clipboard

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

Open RockClimbingRocks opened this issue 3 years ago • 4 comments

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<MirrorTrade>("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);`

RockClimbingRocks avatar Sep 19 '22 07:09 RockClimbingRocks

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

JonathanMagnan avatar Sep 19 '22 13:09 JonathanMagnan

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");

            }
        }
    }
}

RockClimbingRocks avatar Sep 20 '22 11:09 RockClimbingRocks

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: [email protected]

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 avatar Sep 20 '22 13:09 JonathanMagnan

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 avatar Sep 23 '22 14:09 JonathanMagnan

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

JonathanMagnan avatar Sep 30 '22 13:09 JonathanMagnan

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'

csseba avatar Nov 25 '22 23:11 csseba

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

JonathanMagnan avatar Nov 26 '22 14:11 JonathanMagnan

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

csseba avatar Nov 28 '22 17:11 csseba

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.

pawannogariya avatar Sep 14 '23 09:09 pawannogariya

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: [email protected]

Best Regards,

Jon

JonathanMagnan avatar Sep 14 '23 14:09 JonathanMagnan