Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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# 如何在SQLite表的类中将字段标记为可空?_C#_Sqlite_Nullable - Fatal编程技术网

C# 如何在SQLite表的类中将字段标记为可空?

C# 如何在SQLite表的类中将字段标记为可空?,c#,sqlite,nullable,C#,Sqlite,Nullable,对于要用于SQLite数据库的类中应为null的列,是否可以通过追加“”将该列标记为null 如果我想让“季节时间”为空,是这样做的吗 public class PlatypiRUs { [SQLite.PrimaryKey, AutoIncrement] public int Id { get; set; } public string PlatypusId { get; set; } public string PlatypusName { get; set;

对于要用于SQLite数据库的类中应为null的列,是否可以通过追加“”将该列标记为null

如果我想让“季节时间”为空,是这样做的吗

public class PlatypiRUs
{
    [SQLite.PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string PlatypusId { get; set; }
    public string PlatypusName { get; set; }
    public DateTime EOW { get; set; }
    public DateTime? TimeOfTheSeason { get; set; }
}

是的你可以做到

DateTime不能用作常量,但可以改为可为null的类型(DateTime?

给出日期时间?默认值为null,如果在函数开始时将其设置为null,则可以将其初始化为所需的任何值

static void TestMethod(DateTime? dt = null)
{
    if (dt == null)
    {
        dt = new DateTime(1981, 03, 01);
    }

    //...
}
您可以使用命名参数调用它,如下所示:

TestMethod(dt: new DateTime(2010, 03, 01));
TestMethod();
使用默认参数
,如下所示:

TestMethod(dt: new DateTime(2010, 03, 01));
TestMethod();

这是我一直在做的事情,但我很好奇是否还有更“合适”的方式来做。我想你是在使用codefirst吧?如果是这样的话,问号对我来说就像你所展示的一样。毕竟,你可以试试看。PS:FluentNHibernate映射就是这样工作的。@Fauntleroy:如果我在插入记录的时候,我可以,但我只是在设计类/表的时候。