如何在linq查询中为整数列设置空条件。获取整数列的Null引用异常

时间:2017-02-20 05:58:28

标签: vb.net linq

  Dim payorProvidersList = (From pp In payorProviders
                                 Group Join p In accPayors On p.PayorCode Equals pp.PayorCode Into gpPP = Group From p In gpPP.DefaultIfEmpty()
                                 Group Join hpc In hipaaPayorConnectors On hpc.ConnectorId Equals pp.ConnectorID And hpc.PayorCode Equals pp.PayorCode And hpc.TransactionType Equals pp.TransactionType Into gpHPC = Group From hpc In gpHPC.DefaultIfEmpty()
                                 Select New PayorProvidersInfo With
                                    {
                                       .ID = pp.ID,
                                       .PayorCode = pp.PayorCode,
                                       .ProviderId = pp.ProviderId,
                                       .CreatedBy = pp.CreatedBy,
                                       .CreatedDate = pp.CreatedDate,
                                       .UpdatedBy = pp.UpdatedBy,
                                       .UpdatedDate = pp.UpdatedDate,
                                       .ConnectorID = pp.ConnectorID,
                                       .NPI = pp.NPI,
                                       .Order = hpc.Order,
                                       .TransactionType = pp.TransactionType,
                                       .PayorName = If(p IsNot Nothing AndAlso p.PayorName IsNot Nothing, p.PayorName, "Unknown"),
                                       .EmdeonPayorName = If(p IsNot Nothing AndAlso p.EmdeonPayorName IsNot Nothing, p.EmdeonPayorName, "Unknown")}).ToList()

1 个答案:

答案 0 :(得分:0)

hpc.ConnectorId替换为If(hpc.ConnectorId, 0)

修改

根据您的评论,您的问题不是整数字段,而是hpc对象本身。

尝试将hpc.ConnectorId替换为If(hpc is nothing, 0,hpc.ConnectorId)