Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Multiple properties with same column name causes exception #5

Closed
henkmollema opened this issue May 21, 2014 · 3 comments
Closed

Multiple properties with same column name causes exception #5

henkmollema opened this issue May 21, 2014 · 3 comments
Labels

Comments

@henkmollema
Copy link
Owner

For example these models:

public class Product
{
    public int Id { get; set; }
}

public class Order
{
    public int Id { get; set; }
}

With this convention:

public class PrefixConvention : Convention
{
    public PrefixConvention()
    {
        Properties<int>()
            .Where(p => p.Name.ToLower() == "id")
            .Configure(config => config.HasColumnName("autID");
    }
}

Causes an exception which tells you that duplicate mappings are found for the column autID since it finds the PropertyMap instance for Order and Product. A check for the property type should be added to the filter predicate.

@kaanacar34
Copy link

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

@kaanacar34
Copy link

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; }
}

@kaanacar34
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants