asp.net mvc - ?: and ?? Operators with Entity Framework -
why these operators not work within these examples?
person.cityname = personinfo.cities.cityname ?? "-"; or
person.cityname = personinfo.cities.cityname == null ? "-" : personinfo.cities.cityname; view generates system.nullreferenceexception. if not allowed advice?
if cityname column nullable, should check hasvalue property follows. , if like, can check if either personinfo or personinfo.cities null.
person.cityname = personinfo != null && personinfo.cities != null && personinfo.cities.cityname.hasvalue ? personinfo.cities.cityname.value : "-";
Comments
Post a Comment