henkmollema/Dommel

When I map ID to column I can't change key.

maccurt opened this issue · 4 comments

My business object has the property Id, so business.id, my database has the field BusinessId which is the Key and a IndentityColumn

public class BusinessMap : DommelEntityMap<Business>
    {
        public BusinessMap()
        {
            **Map(x => x.Id).ToColumn("BusinessId").IsKey();**
        }
    }

FluentMapper.Initialize(config =>
            {
                config.AddMap(new BusinessMap());
                config.ForDommel();               
            });

When I do an _db.update(business) it says Invalid Column Name ID

I am using Dapper, Dapper.FluentMap and Dapper.FluentMap.Dommel

I am assuming when it is tries to create the update query it is putting "Where Id = 1" but it should be "Where BusinessId = 1"

Is this not supported?

Hi,
with versione 2.3.2 I haven't issue.

public class EntitaMap : DommelEntityMap<EntitaEntity>
    {
        public EntitaMap()
        {
            ToTable("tppEntita");
            Map(u => u.Id).ToColumn("IDEntita").IsKey().IsIdentity();
            Map(u => u.Descrizione).ToColumn("DSEntita");
            Map(u => u.IdOwner).ToColumn("IDOwner");
        }
    }

this is my test

 using (var uow = UnitOfWorkFactory.GetUnitOfWork())
            {
                var entita1 = uow.Entita.Repository.Get(e => e.Id == 1).First();
                entita1.Descrizione = "TEST";

                uow.Entita.Repository.Update(entita1);

            }

and the Update implementation

public void Update(TEntity entity)
        {
            Connection.Update(entity: entity, transaction: Transaction);
        }
2021-08-06 15:26:55,362 [4] INFO  string - Selected SQL Builder 'SqlServerSqlBuilder' for connection type 'SqlConnection'
2021-08-06 15:26:55,400 [4] INFO  string - Resolved table name '[tppEntita]' for 'Dinamo.DataAccess.DINAMO.Entita.EntitaEntity'
2021-08-06 15:26:55,402 [4] INFO  string - Selected SQL Builder 'SqlServerSqlBuilder' for connection type 'SqlConnection'
2021-08-06 15:26:57,628 [4] INFO  string - Resolved column name '[IDEntita]' for 'Int32 Id'
2021-08-06 15:26:59,002 [4] INFO  string - Select<EntitaEntity>: select * from [tppEntita] where ([IDEntita] = @p1)
2021-08-06 15:27:02,650 [4] INFO  string - Selected SQL Builder 'SqlServerSqlBuilder' for connection type 'SqlConnection'
2021-08-06 15:27:02,650 [4] INFO  string - Resolved table name '[tppEntita]' for 'Dinamo.DataAccess.DINAMO.Entita.EntitaEntity'
2021-08-06 15:27:02,657 [4] INFO  string - Resolved property 'Id' as key property for 'Dinamo.DataAccess.DINAMO.Entita.EntitaEntity'
2021-08-06 15:27:03,619 [4] INFO  string - Resolved column name '[IdInsieme]' for 'Dinamo.DataAccess.DINAMO.Insiemi IdInsieme'
2021-08-06 15:27:04,785 [4] INFO  string - Resolved column name '[DSEntita]' for 'System.String Descrizione'
2021-08-06 15:27:05,865 [4] INFO  string - Resolved column name '[Annullato]' for 'Boolean Annullato'
2021-08-06 15:27:06,662 [4] INFO  string - Resolved column name '[IDOwner]' for 'Int32 IdOwner'
2021-08-06 15:27:07,517 [4] INFO  string - Resolved column name '[IDEntita]' for 'Int32 Id'
2021-08-06 15:27:14,175 [4] INFO  string - Update<EntitaEntity>: update [tppEntita] set [IdInsieme] = @IdInsieme, [DSEntita] = @Descrizione, [Annullato] = @Annullato, [IDOwner] = @IdOwner where [IDEntita] = @Id

Interesting, mine does work. What are your Nuget Packages? Your connection.update, what is the extension package for that? I think mine is using .contrib but I did not pull that in, perhaps it is a dependency from some other nuget package

I've installed Dommel 2.3.2, Dapper.Contrib 2.0.78, Dapper.FluentMap.Dommel 2.0.0
My connection.Update refer a Dommel

Ok, I think I got some of it figured out... My .Update was going to the Dapper.Contrib, I then installed Dommel and made is use it's extension. Now I am getting a new error: System.ArgumentNullException: 'Value cannot be null. (Parameter 'source')' I will see if I can figure that out next, I think I am on the right track..