henkmollema / Dapper-FluentMap

Provides a simple API to fluently map POCO properties to database columns when using Dapper.
MIT License
427 stars 86 forks source link

DAPPER FLUENTMAP Multiple properties with same column name causes exception #125

Closed kaanacar34 closed 1 year ago

kaanacar34 commented 3 years ago

My Entities ;

public class Category { public int Id { get; set; } public string Name { get; set; } public string Definition { get; set; } public int ParentId { get; set; }

} public class Brand { public int Id { get; set; } public string Name { get; set; } public string Definition { get; set; } }

{ public int Id { get; set; } // public int UnitId { get; set; } public Unit Unit { get; set; } // public int CategoryId { get; set; } public Category Category { get; set; } // public int BrandId { get; set; } public Brand Brand { get; set; } public string Name { get; set; } public string Definition { get; set; } }

Sql Query;

Select p.Id, p.Name, p.Definition, p.UnitId, u.Name, u.Definition, p.CategoryId, c.Name, c.Definition, p.BrandId, b.Name, b.Definition FROM Products p LEFT join Units u ON p.UnitId = u.Id LEFT JOIN Categories c ON c.Id = p.CategoryId LEFT JOIN Brands b ON b.Id = p.BrandId

public class TypePrefixConvention:Convention { public TypePrefixConvention() {

    Properties<int>()
        .Where(c => c.Name == "Id" )
        .Configure(c => c.HasColumnName("BrandId"));

    Properties<int>()
        .Where(c => c.Name == "Id")
        .Configure(c => c.HasColumnName("CategoryId"));

}

} I want it to match the Id for both categoryId and BrandId.

example: FluentMapper.Initialize(config=>config.AddConvention().ForEntity().ForEntity())

Only the first entity matches for Id.

henkmollema commented 1 year ago

I'm archiving this repository as I'm not using this library myself anymore and have no time maintaining it. Thanks for using it.