1- 我使用linq to sql查询数据库表。
2- 在我的实际表中,我将电话国家代码、电话号码和电话分机存储在不同的列中。
3- 当我获取数据时,我需要电话等于电话国家代码、电话号码和电话分机的连接。
4- 对于某些记录,这3个列中的任何一个可能具有空值。
5- 如果其中一个列为空,则整个连接结果为null。
from s in test
select new{
Phone = s.PhoneCountryCode + s.PhoneNumber + s.PhoneExtension
}
我尝试了以下方法,但没有成功。仍然返回 null 值。
from s in test
select new{
Phone = s.PhoneCountryCode == null ? "" : s.PhoneCountryCode + s.PhoneNumber == null ? "" : s.PhoneNumber + s.PhoneExtension == null ? "" : s.PhoneExtension
}