Home A query body must end with a select clause or a group clause in LINQ Query
Reply: 2

A query body must end with a select clause or a group clause in LINQ Query

ramesh kumar
1#
ramesh kumar Published in 2017-09-14 06:37:41Z
model.ListManagerReviewerMapping = (from a in wallet.OM_Employee 
                                    join m in wallet.APPR_ManagerMapping 
                                    on a.AssociateId equals m.AssociateId
                                    where m.ManagerId==Context.UserId.Value **into** MM 
                                    from leftjoinresult in M.DefaultIfEmpty() 
                                    where a.CompanyId == Context.CompanyId && (a.TermStatus == "L" || a.SeparationDate > DateTime.Today) 
                                    select new ManagerAndReviewerMappingModel.ManagerAndReviewerMapping() 
                                    { 
                                        Photo = (photoUrl + "?AssociateCode=" + a.AssociateCode), 
                                        AssociateId = a.AssociateId,
                                        AssociateCode = a.AssociateCode,
                                        AssociateName = a.AssociateName
                                    }).ToList();
Tetsuya Yamamoto
2#
Tetsuya Yamamoto Reply to 2017-09-14 07:04:05Z

You need to use Where extension method for first query, as the query uses left join with DefaultIfEmpty (note that you can't use into after where clause since where must be followed with select to finish the query):

model.ListManagerReviewerMapping = (from a in wallet.OM_Employee 
                                    join m in wallet.APPR_ManagerMapping.Where(x => x.ManagerId == Context.UserId.Value)
                                    on a.AssociateId equals m.AssociateId into MM 

                                    from leftjoinresult in MM.DefaultIfEmpty() 
                                    where a.CompanyId == Context.CompanyId && (a.TermStatus == "L" || a.SeparationDate > DateTime.Today) 
                                    select new ManagerAndReviewerMappingModel.ManagerAndReviewerMapping() 
                                    { 
                                        Photo = (photoUrl + "?AssociateCode=" + a.AssociateCode), 
                                        AssociateId = a.AssociateId,
                                        AssociateCode = a.AssociateCode,
                                        AssociateName = a.AssociateName
                                    }).ToList();

Similar issues:

LINQ LEFT JOIN where clause not working

LINQ Left Join And Right Join

Manfice
3#
Manfice Reply to 2017-09-14 07:01:53Z
//Remove brackets and .ToList();
model.ListManagerReviewerMapping = from a in wallet.OM_Employee 
                                join m in wallet.APPR_ManagerMapping 
                                on a.AssociateId equals m.AssociateId
                                where m.ManagerId==Context.UserId.Value **into** MM 
                                from leftjoinresult in M.DefaultIfEmpty() 
                                where a.CompanyId == Context.CompanyId && (a.TermStatus == "L" || a.SeparationDate > DateTime.Today) 
                                select new ManagerAndReviewerMappingModel.ManagerAndReviewerMapping() 
                                { 
                                    Photo = (photoUrl + "?AssociateCode=" + a.AssociateCode), 
                                    AssociateId = a.AssociateId,
                                    AssociateCode = a.AssociateCode,
                                    AssociateName = a.AssociateName
                                };
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.367877 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO