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

DAPPER FLUENTMAP Multiple properties with same column name causes exception

Open kaanacar34 opened this issue 4 years ago • 0 comments

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<TypePrefixConvention>().ForEntity<Brand>().ForEntity<Category>())

Only the first entity matches for Id.

kaanacar34 avatar Oct 06 '20 23:10 kaanacar34