Fluent API - 将整数或smallint字段设置为unsigned

时间:2016-06-23 18:33:59

标签: asp.net asp.net-mvc asp.net-mvc-5 ef-fluent-api

当前项目:

  • ASP.NET 4.5.2
  • MVC 5
  • Fluent API

在构建模型本身时,我可以使用正确的方法将字段设置为无符号:

public ushort? NumberEmployees { get; set; }

这将给出0到65,536之间的值,而不是-32768到32,767。

但是,当我使用Fluent API时,对于SQL表,我似乎是limited by what kind of data types I can implement,至少在.hascolumntype("")的情况下。如何通过Fluent API实现unsigned smallint?

到目前为止,该特定字段的Fluent API字符串如下所示:

modelBuilder.Entity<Company>().Property(x => x.NumberEmployees).HasColumnType("smallint").IsOptional();

但显然smallint ushort相同。如果我删除.HasColumnType("")语句,则迁移会抛出错误:

The property 'NumberEmployees' is not a declared property on type 'Company'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.

建议?

0 个答案:

没有答案