0

Right now I am using linq queries in my repository pattern and using the joins like this.

IEnumerable<RecipeModel> listOfRecipe = 
    (
        from objRecipe in db.Recipes
        join SR in db.StandardRecipes on objRecipe.StandardRecipeId equals SR.StandardRecipeId
        into s
        from sr in s.DefaultIfEmpty()
        join O in db.Operators on objRecipe.OperatorId equals O.OperatorId
        into o
        from op in o.DefaultIfEmpty()
        join OL in db.Operators_Locations on objRecipe.OperatorLocationId equals OL.OperatorLocationId
        into l
        from ol in l.DefaultIfEmpty()
        select new RecipeModel()
        {
            RecipeId = objRecipe.RecipeId,
            ProductName = objRecipe.ProductName,
            Variation = objRecipe.Variation,
            CurrentPrice = objRecipe.CurrentPrice,
            LastCost = objRecipe.LastCost,
            Description = objRecipe.Description,
            RecipeName = sr.RecipeName,
            OperatorNameFirm = op.OperatorNameFirm,
            LocationName = ol.LocationName,
            date_creation = objRecipe.date_creation,
            created_by = objRecipe.created_by,
            modified_by = objRecipe.modified_by,
            date_modified = objRecipe.date_modified
        }
    ).ToList();
return listOfRecipe;

Now I want to use these joins with automapper.

Self
  • 349
  • 1
  • 8
Amit Raj
  • 1
  • 1
  • 1
    I put it in a code block... but you should fix it more. – JHBonarius Mar 02 '21 at 07:42
  • What I have to do next if i want to use automapper with these joins for getting the perfect data. – Amit Raj Mar 02 '21 at 07:44
  • 1
    I will advice using [ask], and [mre]. We just have one sentence and a block of code. Title is just the 3 tokens: "leftjoin", "automapper", "repository". The first sentece is "repository", "leftjoin". The sencond sentence is "leftjoin", "automapper". The clarification comment is "automapper", "leftjoin". – Drag and Drop Mar 02 '21 at 07:46
  • but what my concern is how to use left join in automapper. – Amit Raj Mar 02 '21 at 07:49
  • I think we got that. We perhaps need elements to answers more that the description of the issue. Just read the guide line they are really good at constructing a question. I use it every day even outside of Stackoverflow. What can be interessting is the class that you can to map in automapper. https://stackoverflow.com/questions/41368164/automapper-to-join-records-from-2-tables-into-single-ienumerable-viewmodel – Drag and Drop Mar 02 '21 at 07:51
  • Repeating your intention will not give you the result. You don't have a clear focused question. What is the problem with the current code? – JHBonarius Mar 02 '21 at 08:16
  • 1
    This might interest you: https://docs.automapper.org/en/stable/Queryable-Extensions.html –  Mar 02 '21 at 08:57
  • Thanks knoop. I think by this i can solve my problem. – Amit Raj Mar 02 '21 at 09:01

0 Answers0