如何使用ServiceStack OrmLite设置外键以允许空值?

时间:2014-06-15 18:28:56

标签: servicestack ormlite-servicestack

我正在使用ServiceStack v4.x VS2013

默认情况下,ServiceStack ORMLite(SqlServer)使用" NOT NULL"定义外键。 以下代码生成一个外键" FooId(FK,long,not null)" 如何告诉ServiceStack这个外键可能为空?

public class Blah
{
    [AutoIncrement]
    public long Id { get; set; }
    public string Name { get; set; }

    [References(typeof(Foo))]
    public long FooId { get; set; }

}

public class Foo
{
    [AutoIncrement]
    public long Id { get; set; }
    public string Description { get; set; }
}

1 个答案:

答案 0 :(得分:1)

要在OrmLite中指定值类型可以为空,请在C#中使其可为空:

public class Blah
{
    [AutoIncrement]
    public long Id { get; set; }
    public string Name { get; set; }

    [References(typeof(Foo))]
    public long? FooId { get; set; }

}