English 中文(简体)
如果发现某一项物品,LINQ是否使用LEFT JOIN或违约而告无效?
原标题:Can LINQ expression use LEFT JOIN or default to null if item isn t found?

I m trying to track down a crash in some existing code in a web app I inherited.. I ve traced this down to a single LINQ expression:

var projInfo = (from v in context.TPM_PROJECTVERSION
                join p in context.TPM_PROJECT on v.PROJECTID equals p.PROJECTID
                join pto in context.TPM_USER on v.TPM_USER1.USERID equals pto.USERID
                join pt in context.TPM_PROJECTTYPES on p.PROJECTTYPEID equals pt.PROJECTTYPEID
                where v.PROJECTID == projectId && v.VERSIONID == versionId
                select new
                {
                    ProjectName = v.NAME,
                    ProjectType = pt.SHORTNAME,
                    ProjectDesc = v.DESCRIPTION,
                    BusinessLaunchData = p.BUSINESSLAUNCHDATE,
                    BusinessSponsor = (v.TPM_USER3.FIRSTNAME + " " + v.TPM_USER3.LASTNAME),
                    PrimaryTrainingOwner = (pto.FIRSTNAME + " " + pto.LASTNAME)
                }).First();

错误是“数量不包括任何内容”,我已追查到这一行:

join pto in context.TPM_USER on v.TPM_USER1.USERID equals pto.USERID

如果美国电力局1 无效,则该行不会归还。 相反,我只需要掌握初级知识,而只是作废或空白。 基本上,我需要做的是教育、青年和体育部,并在确定初级人才时对此进行检查。 是否有办法更新该准则的表述,以处理这一问题? 感谢!

最佳回答

我认为我找到了解决办法。 我不胜感激,对这是否是最佳办法或合成物或以何种方式? 感谢!

var projInfo = (from v in context.TPM_PROJECTVERSION
                join p in context.TPM_PROJECT on v.PROJECTID equals p.PROJECTID
                join pto in context.TPM_USER on v.TPM_USER1.USERID equals pto.USERID into primaryowner
                from subpto in primaryowner.DefaultIfEmpty()
                join pt in context.TPM_PROJECTTYPES on p.PROJECTTYPEID equals pt.PROJECTTYPEID
                where v.PROJECTID == projectId && v.VERSIONID == versionId
                select new
                {
                    ProjectName = v.NAME,
                    ProjectType = pt.SHORTNAME,
                    ProjectDesc = v.DESCRIPTION,
                    BusinessLaunchData = p.BUSINESSLAUNCHDATE,
                    BusinessSponsor = (v.TPM_USER3.FIRSTNAME + " " + v.TPM_USER3.LASTNAME),
                    PrimaryTrainingOwner = subpto == null ? String.Empty : (subpto.FIRSTNAME + " " + subpto.LASTNAME)
                }).First();
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签