-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Description
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."}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels