int? and int comparison when LEFT OUTER JOIN in Linq issue

前端 未结 2 1253
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 10:53

I am working on a WinForms project which requires to use Linq-To-Sql. I have been able to create my DataContext using the SqlMetal tool, and make s

2条回答
  •  北海茫月
    2020-12-22 11:17

    You can use GetValueOrDefault() method. It retrieves the value of the current Nullable object, or the object's default value.

    In terms of your example :

    var query = from p in db.ParentTable
                join t in db.ChildTable on new {A = p.child_ID.GetValueOrDefault(0), B = p.OtherID}
                equals new {A = t.ID, B = t.OtherID} into j1
                from c in j1.DefaultIfEmpty()
                select new
                {
                    ...
                };
    

    If the p.child_ID become null than it will return 0. Hope this will help !!

提交回复
热议问题