Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is it easy to change JOIN into 'LEFT JOIN'?
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Is it easy to change JOIN into 'LEFT JOIN'?
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01640358
Message ID:
01640358
Vues:
57
UPDATE. Going to try suggestions from 42 points answer:

http://stackoverflow.com/questions/584820/how-do-you-perform-a-left-outer-join-using-linq-extension-methods


I was eventually able to make it to work.


Hi everybody,

We have the following code (written long time ago by the previous developers, I think):
globalFunctions = _rolesAdapter.GetSecurityRightsForRole(SysManagerConstants.GLOBAL_DEFAULTS_ROLE_NUMBER, "SecFunc").
                Select(secRight => new FuncViewModel()
                {
                    Descrip = secRight.SecFunc.Descrip,
                    FuncCode = secRight.SecFunc.FuncCode,
                    Grouping = secRight.SecFunc.Grouping,
                    Progmodule = secRight.SecFunc.Progmodule,
                    SubCat = secRight.SecFunc.SubCat,
                    GrantPerm = secRight.GrantPerm
                }).OrderBy(x => x.Descrip);

            //Unassigned
            editSecRoleViewModel.UnassignedFunctions = editSecRoleViewModel.UnassignedFunctions.Join(globalFunctions, uf => uf.FuncCode, gf => gf.FuncCode,
                    (uf, gf) => new FuncViewModel()
                    {
                        Descrip = uf.Descrip,
                        FuncCode = uf.FuncCode,
                        Grouping = uf.Grouping,
                        Progmodule = uf.Progmodule,
                        SubCat = uf.SubCat,
                        GrantPerm = (byte)(gf.GrantPerm | uf.GrantPerm),
                        DefaultGrantPerm = gf.GrantPerm
                    }).OrderBy(x => x.Descrip);
The problem I'm running into right now is that some new functions were not added into the security rights table. So, if there are 216 UnassignedFunctions and 213 global functions, 3 functions will be automatically eliminated by that JOIN.

I am wondering how should I change the code above to always return all rows (e.g. essentially switching LINQ JOIN into LINQ LEFT JOIN)?

I'll be doing research on this question in the meantime, but any help will be appreciated.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform