I'm trying to query one to many on dapper but for some reason I only get 1 value back from my joined table even though I should be getting multiple as from my query Can someone tell me what I did wrong?
I tried doing what was mentioned in the following post answer Mapping one to many with Dapper
My code:
public class MonsterDatabase { public int Id { get; set; } public int MonsterId { get; set; } public string Name { get; set; } public List<MonsterLocationDatabase> Location { get; set; } } public class MonsterLocationDatabase { public int Id { get; set; } public int FkMonsterId { get; set; } public string Map { get; set; } public int Frequency { get; set; } public string MapImage { get; set; } public DateTime? DeathTime { get; set; } public DateTime? RespawnTime { get; set; } } public static MonsterDatabase GetMonster(Monster monster) { using (var connection = new SqlConnection(config["appsettings:RagnaDatabase"])) { var Monster = connection.Query<MonsterDatabase, MonsterLocationDatabase, MonsterDatabase>( "select top 1 Monster.*, SplitMonster = '', MonsterLocation.*" + " from Monster" + " join MonsterLocation" + " on Monster.Id = MonsterLocation.FkMonsterId", (Monster, Location) => { Monster.Location = new List<MonsterLocationDatabase>(); Monster.Location.Add(Location); return Monster; }, splitOn: "SplitMonster" ).FirstOrDefault(); return Monster; } } 
.FirstOrDefaultreturns one resultsplitOn: "SplitMonster"makes no sense because that column does not change. It needs to be a column which changes from one child object to the next. Also you haveselect top 1which will only return one row anywayvar Monster = ...but that seems to be the type of themonstervariable being passed in to theGetMonstermethod.