0

I have SQL Query ready, and that I want its result into a complex SQL object. I want to use Linq to achieve the result.

public class VMPackageList
{
    public string PackageName { get; set; }
    public string ShortTitle { get; set; }  
}

public class VMPackageItenary
{
    public string PackageName { get; set; }
    public string Day { get; set; }
    public string Title { get; set; }
    public string Detail { get; set; }
}

public class VMPackageHighlight
{
    public string PackageName { get; set; }
    public string Highlightname { get; set; }
    public string HighlightDesc { get; set; }
}

The expected result in below class

public class VMPackageDetails
{
    public VMPackageList vmPackage { get; set; }
    public VMPackageItenary[] vmPackageItenary { get; set; }
    public VMPackageHighlight[] vmPackageHighlights { get; set; }
}

Below are the SQL query and its result, the same way I want to get into SQL table data query

This is my result query

I had tried with below code to achieve but I did not get success

var packages = packageRepository.Table;
            var highlights = packageHighlightRepository.Table;
            var itenaries = packageItenaryRepository.Table;

            var data = (from package in packages
                        join highlight in highlights on package.PackageName equals highlight.PackageName
                        join iteratory in itenaries on package.PackageName equals iteratory.PackageName //&&
                        where package.PackageName == packageName //&& highlight.PackageName equals iteratory.PackageName
                       select new VMPackageDetails
                        {
                            // vmPackage = package
                        }).ToList();

Can anyone help me to get the result?

  • The linked image that you said you want as a result, comes from 3 queries, but it looks like you are after a single query that returns everything, including children entities. Have you tried this: https://stackoverflow.com/questions/3356541/entity-framework-linq-query-include-multiple-children-entities – Frank Fajardo Dec 18 '20 at 01:43
  • It is similar to your question: https://stackoverflow.com/a/65336661/10646316 – Svyatoslav Danyliv Dec 18 '20 at 11:41

0 Answers0