我有以下方法:C#.NET 4.0:可爲空輸入字符串參數和Lambda表達式
public IQueryable<Profile> FindAllProfiles(string CountryFrom, string CountryLoc)
{
return db.Profiles.Where(p => p.CountryFrom.CountryName.Equals(CountryFrom,StringComparison.OrdinalIgnoreCase));
}
現在,它只是CountryFrom過濾器,但我需要CountryLoc對其進行過濾以及。 那麼如何修改Where過濾器?
另外,CountryFrom可以爲null或CountryLoc可以爲null。那麼如何修改方法的簽名到所有可爲空的輸入字符串參數。
我知道如何做到這一點在SQL中,但我不確定有關lambda表達式或LINQ。
謝謝
檢查空值我認爲提問者關心Equals方法拋出NullReferenceException。 – EMP 2010-07-07 03:56:16