henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
611 stars 99 forks source link

Problem with Left Join #116

Closed AlefHortela closed 5 years ago

AlefHortela commented 5 years ago

Hello Henk, I've having a problem on "left" and "inner" joins on MultiMap, it's always returning a inner join and a need a left join on my query.

here is the code.

        {
            using (var db = new NpgsqlConnection(ConnectionString))
            {

                var stationDictionary = new Dictionary<int, Station>();

                var result = db.Get<Station, Package, Station>(id, (station, package) =>
                {
                    Station stationEntry;

                    if (!stationDictionary.TryGetValue(station.Id, out stationEntry))
                    {
                        stationEntry = station;
                        stationEntry.Packages = new List<Package>();
                        stationDictionary.Add(id, stationEntry);
                    }

                    stationEntry.Packages.Add(package);
                    return stationEntry;
                });

                return result;
            }
        }

here is the entities

    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Desc { get; set; }

        public ICollection<Package> Packages { get; set; } = new List<Package>();
    }

    public class Package
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Desc { get; set; }

        public int StationId { get; set; }
        public Station Station { get; set; }
    }

here is the maps

        {
            ToTable("package");
            Map(c => c.Id).ToColumn("id").IsKey().IsIdentity();
            Map(c => c.Name).ToColumn("nm_name");
            Map(c => c.Desc).ToColumn("nm_description");
            Map(c => c.StationId).ToColumn("id_station");
            Map(c => c.Station).Ignore();
        }

        public StationMap()
        {
            ToTable("station");
            Map(c => c.Id).ToColumn("id").IsKey().IsIdentity();
            Map(c => c.Name).ToColumn("nm_name");
            Map(c => c.Desc).ToColumn("nm_description");
        }

It always returning me a inner join, I needed to put a "?" in StationId on Package to get a left join. probably i'm making some mistakes on my code, could you help me?

Thanks and keep with the great work :)

henkmollema commented 5 years ago

@AlefHortela this is fixed in Dommel v2. You might want to try that out. The latest version is 2.0.0-beta4 and is available on NuGet.