Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle Left joins #34

Open
Mech0z opened this issue May 24, 2016 · 0 comments
Open

How to handle Left joins #34

Mech0z opened this issue May 24, 2016 · 0 comments

Comments

@Mech0z
Copy link

Mech0z commented May 24, 2016

                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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant