I’m trying to get datetime value but here is issue with nullable datetype. How to fix that?
Public Function GetDate(ByVal kodg As Integer) As DateTime
Dim g = From dt In db.xDates _
Join f In db.xGrafiks On dt.КодД Equals f.DateKod _
Where f.Kod = kodg
Select New Date?(dt.Дата) ???
Return g ???
End Function
gwill be aIQueryable(Date?), which is a collection, so you first have to check if there is a value. You can do this by usingFirstOrDefault()(if there can be multiple results or none), orSingleOrDefault(if there shouldn’t be multiple resulst).Then you get one
Date?back. You can then use theHasValueproperty to check if theDate?has a value, if that’s true just return it. If not you should return anotherDatefrom your function (maybeDateTime.MinValue?).Or you could change the return value of your function to be a
Date?and the just return the nullable date from your query.