neo*_*neo 3 c# linq linq-to-sql
1-我使用linq to sql来查询数据库表.
2-在我的实际表中,我将电话国家代码,电话号码和电话分机存储在不同的列中.
3-当我得到数据时,我需要Phone等于电话国家代码,电话号码和电话分机的串联.
4-对于某些记录,这3列中的任何一列都可能具有空值.
5-如果一列为null,则整个连接产生null.
from s in test
select new{
Phone = s.PhoneCountryCode + s.PhoneNumber + s.PhoneExtension
}
Run Code Online (Sandbox Code Playgroud)
6-我尝试了以下,但没有奏效.仍然产生无效.
from s in test
select new{
Phone = s.PhoneCountryCode == null ? "" : s.PhoneCountryCode + s.PhoneNumber == null ? "" : s.PhoneNumber + s.PhoneExtension == null ? "" : s.PhoneExtension
}
Run Code Online (Sandbox Code Playgroud)
您可以??按如下方式使用运算符:
from s in test
select new
{
Phone = (s.PhoneCountryCode ?? "") + (s.PhoneNumber ?? "") + (s.PhoneExtension ?? "")
}
Run Code Online (Sandbox Code Playgroud)