2

I have a legacy database that uses the smalldatetime SQL data type. That maps fine to the standard DateTime. However, when I use SchemaExport, it understandably generates the column with datetime format. What custom type should I be using in my mapping so that the generated column is smalldatetime?

   // Does not work as custom type not known       
   Map(x => x.BirthDate).Column("dtBirthDate").Not.Nullable().CustomType("smalldatetime");
Ted
  • 7,122
  • 9
  • 50
  • 76

1 Answers1

1

You almost had it, instead of .CustomType you'll have to define .CustomSqlType

Map(x => x.BirthDate)
    .Column("dtBirthDate")
    .Not.Nullable()
    .CustomSqlType("smalldatetime")
    .CustomType("datetime")

Just tested it and it will create a database column with smalldatetime.

MichaC
  • 13,104
  • 2
  • 44
  • 56
  • Perfect. Thought there was an equivalent to something like .CustomType("AnsiString") for varchar. I was going to try CustomSqlType, but I'm glad I didn't as I wouldn't have thought of adding CustomType("datetime") as well. I'm assuming this would also be the way to roll with i.e. smallint (CustomerSqlType("smallint").CustomType("int")). – Ted Oct 03 '13 at 23:39
  • And FYI for anyone else coming after, you can do the same with enum mappings with a bit of a twist (because if you're already doing a custom enum mapper, you'll already have defined the CustomType). For example, with a byte enum, Map(x => x.Season).Column("SomeTinyIntColumn").CustomType().CustomSqlType("tinyint")... – Ted Oct 03 '13 at 23:52