Skip to content

Mapping many to many gives error #31

@Mech0z

Description

@Mech0z

I have some query that goes like

select *
    from "AnalysisRules" 
    join "AnalysisCategory" on "AnalysisRules"."AnalysisCategoryId" = "AnalysisCategory"."Id"  
    join "Analysis" on "AnalysisRules"."AnalysisId" = "Analysis"."Id"
    left join "AnalysisRulesBreeds" on "AnalysisRulesBreeds"."AnalysisRuleId" = "AnalysisRules"."Id"
    left join "Breed" on "AnalysisRulesBreeds"."BreedId" = "Breed"."Id"
    where "AnalysisId" = 200;

This gives me 2 rows, so I need those 2 rows to be squashed into 1 list in my AnalysisRule object

The important part is
left join ""AnalysisRulesBreeds"" on ""AnalysisRulesBreeds"".""AnalysisRuleId"" = ""AnalysisRules"".""Id""
left join "Breed" on "AnalysisRulesBreeds"."BreedId" = "Breed"."Id"

AnalysisRulesBreeds has 3 columns, Id, BreedId and AnalysisRuleId

This table AnalysisRulesBreeds holds my many to many relations, but how do I map this with Slapper?

I tried this

`                    var sql = @"select *
                                from ""AnalysisRules"" 
                                join ""AnalysisCategory"" on ""AnalysisRules"".""AnalysisCategoryId"" = ""AnalysisCategory"".""Id""  
                                join ""Analysis"" on ""AnalysisRules"".""AnalysisId"" = ""Analysis"".""Id""
                                left join ""AnalysisRulesBreeds"" on ""AnalysisRulesBreeds"".""AnalysisRuleId"" = ""AnalysisRules"".""Id""
                                left join ""Breed"" on ""AnalysisRulesBreeds"".""BreedId"" = ""Breed"".""Id""
                                where ""AnalysisId"" = :AnalysisId";
                    IEnumerable<dynamic> analysisRules = sqlConnection.Query<dynamic>(
                        sql,
                        new
                        {
                            AnalysisId = analysisId
                        });

                    Slapper.AutoMapper.Configuration.IdentifierConventions.Add(type => type.Name + "Id");

                    IEnumerable<AnalysisRule> testContact = Slapper.AutoMapper.MapDynamic<AnalysisRule>(analysisRules);`

AnalysisRule is as follow

    public class AnalysisRule
    {
        public AnalysisRule()
        {
            Breeds = new List<Breed>();
        }

        public long Id { get; set; }
        public Analysis Analysis { get; set; }
        public AnalysisCategory AnalysisCategory { get; set; }
        public Gender Gender { get; set; }
        public bool FatherHerdBookRequired { get; set; }
        public bool MotherHerdBookRequired { get; set; }
        public List<Breed> Breeds { get; set; }
    }

But I just get

{"An item with the same key has already been added."}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions