开发者

nullable object must have a value error assigning linq query result to variable

I've created a variable o开发者_如何学Cf a class type (CustomerInfo) to store a linq query result and get the error message 'nullable object must have a value' when I view or use the colResults variable, (SurveyDate is a nullable field in the sql table):

        Dim var = SurveyDBcontext.QT_Survey_GetSurveySchedule(1, 1, 1).ToList()
        Dim colResults = From query In var _
                         ...      _                       
                         Select New CustomerInfo With { _
                            .Address = comp.Address, _
                            .SurveyDate= query.SurveyDate}

If I change the above to:

        Dim colResults = From query In var _
                         ...      _                       
                         Select New With { _
                            .Address = comp.Address, _
                            .SurveyDate= query.SurveyDate}

if works fine. Any ideas?

thanks.


Your 'Address' or 'ServeyDate' fields are returning null values and your CustomerInfo class does not allow null values.

The second example is generating an anonymous type which allows nulls. Can you check the actual type that is generated? Guessing SurveyDate is a nullable DateTime in the second example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜