0

我有以下SQL查询

Select LC.*,LP.[LandingPageName] from [LandingPageCompanies] LC
 Left join [LandingPageContent] LP on LP.SubCategoryID=LC.SubCategoryID
 where  LC.[CategoryID]=17

我需要将其转换为LINQ to entity.

我已经尝试了以下查询,但它的工作原理是Inner join

 var data = (from t1 in dbSavingContainer.LandingPageCompanies
                        join t2 in dbSavingContainer.LandingPageContents on t1.SubCategoryID equals t2.SubCategoryID
                        where t1.CategoryID == CategoryID
                        select new
                        {
                            CategoryID = t1.CategoryID,
                            CompanyID = t1.CompanyID,
                            CompanyLink = t1.CompanyLink,
                            CompanyLogo = t1.CompanyLogo,
                            CompanyName = t1.CompanyName,
                            SubCategoryID = t1.SubCategoryID,
                            LandingPageName = t2.LandingPageName
                        }).ToList();

我缺乏的地方。?

4

1 回答 1

1

谢谢..我刚刚使用以下查询解决了它;)

 var data = (from t1 in dbSavingContainer.LandingPageCompanies
             join t2 in dbSavingContainer.LandingPageContents on t1.SubCategoryID equals t2.SubCategoryID
             into x from y in x.DefaultIfEmpty()
                   where t1.CategoryID == CategoryID
                     select new
                      {
                        CategoryID = t1.CategoryID,
                        CompanyID = t1.CompanyID,
                        CompanyLink = t1.CompanyLink,
                        CompanyLogo = t1.CompanyLogo,
                        CompanyName = t1.CompanyName,
                        SubCategoryID = t1.SubCategoryID,
                        LandingPageName = y.LandingPageName
                    }).ToList();
于 2013-03-22T11:37:17.507 回答