I have a Place object.
It can have many Tags associated with it.
Tags can be associated with many Places.
(Although this is a many to many relationship - I guess conceptually it may as well be a one to many - a collection of objects - with each object containing a collection of objects).
Each Place object has a List collection associated with it:
public class Place
{
public Guid Id { get; set; }
public string PlaceName { get; set; }
...
public List<Tag> Tags { get; set; }
}
public class Tag
{
public Guid Id { get; set; }
public string TagName { get; set; }
}
SQL that selects required data from many to many relationship:
select * from place p
inner join tagplace tp on tp.placeid = p.id
inner join tag t on t.id = tp.tagid
order by placename
Can I map all of this in a single Dapper command (or at least not n+1 commands)? The Github documentation covers one to many relationships - but not many to many.
(The reason I need to do this - is because I want to output a grid of all places, and I want one column to be a comma separated list of tags (I will create a Helper that takes a collection of tags and outputs a comma separated string).
I have seen a similar question where Slapper.AutoMapper is recommended:
How do I write one to many query in Dapper.Net?
I would rather avoid using additional libraries if possible - but I guess it may be required here?
Whats the best way to approach this?