Skip to content

How to handle Left joins #34

Open
Open

Description

@Mech0z
                var sql = @"select  p.*,

                                    a.""Id"" as ""Analysis_Id"",
                                    a.""Name"" as ""Analysis_Name"",
                                    a.""SortOrder"" as ""Analysis_SortOrder""

                                    from ""Product"" p

                                    left join ""Analysis"" a on p.""AnalysisId"" = a.""Id""

                                    where p.""CategoryId"" = :CategoryId";

                IEnumerable<dynamic> dynamicProducts = await
                        sqlConnection.QueryAsync<dynamic>(
                            sql,
                            new
                            {
                                CategoryId = categoryId
                            });

                var products = AutoMapper.MapDynamic<Product>(dynamicProducts).ToList();
                return products;

    public class Product
    {
        public long Id { get; set; }
        public long OFId { get; set; }

        public string Header { get; set; }
        public string Description { get; set; }

        public int CategoryId { get; set; }
        public Analysis Analysis { get; set; }
        public bool IsActive { get; set; }
    }

If AnalysisId is null, then Slapper.Automapper creates a new object with default values. How am I supposed to make it set Analysis to null instead of a "nulled" object?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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