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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -