我有以下方法:C#处理所有可能的零和非NULL值
public IQueryable<Profile> FindAllProfiles(string CountryFrom, string CountryLoc)
{
return db.Profiles.Where(p => p.CountryFrom.CountryName.Equals(CountryFrom,
StringComparison.OrdinalIgnoreCase));
}
什么是写的最好的方式其中条款,将滤波器的输入参数的所有可能的组合在一声明:
BOTH CountryFrom和CountryLoc = NULL
只有CountryFrom空
Only CountryLoc null
BOTH CountryFrom和CountryLoc不为空。
很快..我需要按年龄,性别,职业筛选配置文件..你的名字。
我正试图找到一种方法在C#中高效地编写它。我知道如何在TSQL中以干净的方式做到这一点。我希望我知道的方式。感谢迄今为止的所有回应。
[c#.net 4.0:可为空的输入字符串参数和lambda表达式。](http:// stackoverflow。com/questions/3191687/c-net-4-0-nullable -input-string-parameter-and-the-lambda-expressions) – 2010-07-07 16:19:42
请考虑更新你以前的问题,并要求更清楚,而不是创建一个副本。 – 2010-07-07 16:20:46
是的,看起来非常相似,尽管你的三个问题中的第一个是不同的。尽量避免任何看起来像双重张贴的东西。 – Noldorin 2010-07-07 16:21:18