Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果值为空,则使用Dapper返回日期_C#_Dapper - Fatal编程技术网

C# 如果值为空,则使用Dapper返回日期

C# 如果值为空,则使用Dapper返回日期,c#,dapper,C#,Dapper,如果此字段为空,如何使用Dapper返回日期 这是我的方法,当我将输出返回到该方法时,只缺少一些内容,请参见图片。。我不知道我做错了什么 我的方法: public DateTime GetArbeitStart(int userId) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection()) { connection.Conn

如果此字段为空,如何使用Dapper返回日期

这是我的方法,当我将输出返回到该方法时,只缺少一些内容,请参见图片。。我不知道我做错了什么

我的方法:

    public DateTime GetArbeitStart(int userId)
    {
        using (IDbConnection connection = new System.Data.SqlClient.SqlConnection())
        {
            connection.ConnectionString = _ConnectionString;
            var output = connection.Query<DateTime>("select LPE_ArbeitStart from A_PERSONAL WHERE LPE_ID=" + userId).FirstOrDefault();

            return output == null ? new DateTime(2018, 1, 1);
        } 
    }
public DateTime GetArbeitStart(int userId)
{
使用(IDbConnection connection=new System.Data.SqlClient.SqlConnection())
{
connection.ConnectionString=\u ConnectionString;
var output=connection.Query(“选择LPE_ArbeitStart from_PERSONAL,其中LPE_ID=“+userId”).FirstOrDefault();
返回输出==null?新日期时间(2018,1,1);
} 
}

据我所知,您似乎在尝试将a与

我认为您只需要空合并运算符:

return output ?? new DateTime(2018, 1, 1); 
return output == null ? new DateTime(2018, 1, 1) : output;
或者,如果需要更详细的三元运算符:

return output ?? new DateTime(2018, 1, 1); 
return output == null ? new DateTime(2018, 1, 1) : output;

据我所知,你们似乎在试图把a和a结合起来

我认为您只需要空合并运算符:

return output ?? new DateTime(2018, 1, 1); 
return output == null ? new DateTime(2018, 1, 1) : output;
或者,如果需要更详细的三元运算符:

return output ?? new DateTime(2018, 1, 1); 
return output == null ? new DateTime(2018, 1, 1) : output;

三元运算符中缺少
else
部分

返回输出===null?新日期():somethingElse;

三元运算符中缺少
else
部分

返回输出===null?新日期():somethingElse;

这里是另一种选择:

public DateTime GetArbeitStart(int userId)
{
    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection())
    {
        connection.ConnectionString = _ConnectionString;
        return connection.Query<DateTime>("select LPE_ArbeitStart from A_PERSONAL WHERE LPE_ID=" + userId)
            .DefaultIfEmpty(new DateTime(2018, 1, 1)).First();
    } 
}
public DateTime GetArbeitStart(int userId)
{
使用(IDbConnection connection=new System.Data.SqlClient.SqlConnection())
{
connection.ConnectionString=\u ConnectionString;
return connection.Query(“选择LPE_ArbeitStart from_PERSONAL,其中LPE_ID=“+userId”)
.DefaultIfEmpty(新日期时间(2018,1,1)).First();
} 
}

我喜欢它真正的声明性。

这里是另一种选择:

public DateTime GetArbeitStart(int userId)
{
    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection())
    {
        connection.ConnectionString = _ConnectionString;
        return connection.Query<DateTime>("select LPE_ArbeitStart from A_PERSONAL WHERE LPE_ID=" + userId)
            .DefaultIfEmpty(new DateTime(2018, 1, 1)).First();
    } 
}
public DateTime GetArbeitStart(int userId)
{
使用(IDbConnection connection=new System.Data.SqlClient.SqlConnection())
{
connection.ConnectionString=\u ConnectionString;
return connection.Query(“选择LPE_ArbeitStart from_PERSONAL,其中LPE_ID=“+userId”)
.DefaultIfEmpty(新日期时间(2018,1,1)).First();
} 
}

我喜欢它真的是声明性的。

在输出不为空的情况下,你会怎么做?你错过了“else”部分@john如果是零值,我想返回日期(2018,1,1)@MaxB你能装饰我吗?你应该使用不同的运算符,在输出不为null的情况下你怎么办?你错过了“else”部分@john如果是零值,我想返回日期(2018,1,1)@MaxB你能装饰我吗?你应该使用不同的运算符,