You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The request here is to make navigation properties more flexible:
publicclassStudent{publicCourseFavoriteCourse{get;set;}// This could be null.}
In functional programming, we are taught to be more explicit on whether or not a reference type object is null, so we wrap them in a Maybe<T> monad, that works more-or-less like Nullable<T>.
publicclassStudent{privateCourse_favoriteCourse;// Backing field remains of the same type.publicMaybe<Course>FavoriteCourse=>_favoriteCourse;// Maybe<T> provides implicit conversion.}
Use it like this:
Maybe<Course>favCourseOrNothing=student.FavoriteCourse;if(favCourseOrNothing.HasNoValue)returnError("Bad student doesn't have a favorite course");CoursefavCourse=favCourseOrNothing.Value;// Throws exception if null, preventing us from walking around with null objects.
EF Core doesn't know how to convert Maybe<T> to T, so it gives an exception when building the model.
But, since EF Core works primarily on top of backing fields (and we actually map to the backing field), something like that is totally possible.
See discussion here: https://github.com/dotnet/efcore/discussions/22364
Related: #240 #752
The text was updated successfully, but these errors were encountered: