小编Chr*_*ris的帖子

如何检查许多参数是否为 null 或空字符串?- C#

我有下面的方法,我需要检查参数是否为空或为空。

    public DB Where(string field, string operat, string value, string andOr, string field2, string operat2, string value2)
    {
        _Where = " WHERE " + field + " " + operat + " @" + field + "1 " + andOr + " " + field2 + " " + operat2 + " @" + field2 + "2 ";
        _Params.Add(field + "1", value);
        _Params.Add(field2 + "2", value2);
        return this;
    }
Run Code Online (Sandbox Code Playgroud)

我找到了 string.IsNullOrWhiteSpace 方法,但这需要这么多代码:

                   if (string.IsNullOrWhiteSpace(field))
            throw new ArgumentException("field Cannot be null …
Run Code Online (Sandbox Code Playgroud)

c# string null isnullorempty

3
推荐指数
1
解决办法
6439
查看次数

在EF查询中添加DateTime和TimeSpan的代码示例

我正在寻找这个问题的代码示例.

在LINQ中使用DateTime.Add(TimeSpan)

我需要将一个完整的TimeSpan添加到DateTime.

我已经尝试了,SqlFunctions.DateAdd("ss", SqlFunctions.DatePart("s", b.duration)但这看起来只是添加了TimeSpan的秒部分.

这是我到目前为止的代码

var queryClash = from b in db.calEvents
                where (newEvent.startTime <= (SqlFunctions.DateAdd("ss", SqlFunctions.DatePart("ss", b.duration), b.startTime)))
                && (newEventEndTime >= b.startTime)
                select b;
Run Code Online (Sandbox Code Playgroud)

c# linq datetime entity-framework

3
推荐指数
1
解决办法
1364
查看次数

标签 统计

c# ×2

datetime ×1

entity-framework ×1

isnullorempty ×1

linq ×1

null ×1

string ×1