日期:2014-05-20  浏览次数:20728 次

SQL中的 is null 在linq中怎么表示
各位大哥,小弟想问下在 sql中的 where coulumn is null这个语句用linq应该怎么写,急用

------解决方案--------------------
C# code

   //可空类型用 Nullable<T>.Equals  
   //如:public int? Currency_User_ID 
   where Nullable<int>.Equals(e.Currency_User_ID,变量)

   //引用类型用Nullable.Equals。
   //public string Currency_User_ID 
   where Nullable.Equals(e.Currency_User_ID, 变量)

------解决方案--------------------
探讨

引用:

where vt.Currency_User_ID==null || vt.Currency_User_ID == curr.USER_ID

错了错了,要先判断是否为空,然后才能去跟实际的值比较

不行,where vt.Currency_User_ID==null||vt.Currency_User_ID == curr.USER_ID
……

------解决方案--------------------
C# code

            var query = from t in T
                        where string.IsNullOrEmpty(t.CURRENCY_USER_ID.ToString()) == true
                        | Convert.ToInt32(t.CURRENCY_USER_ID)==42
                        select t;

------解决方案--------------------
where vt.Currency_User_ID == curr.USER_ID || vt.Currency_User_ID.value ==null