0

On an already in place table in the database we are trying to Add a column for the CreationDate

mapping.Map(x => x.CreationDate)
            .Not.Nullable()
            .Default("to_date('01-01-0001','dd-MM-yyyy')")

This works perfectly fine with oracle but SQLite will not understand this, which is perfectly normal because it does not know the to_date() function.

If i use

DateTime.MinValue.ToString()

for the Default value with or without an specific format. Then it will work in SQLite but it wont work in Oracle.

Does someone know a solution to solve this.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37

1 Answers1

1

leave out the defaultvalue and write a convention

class CreationDateConvention  : IPropertyConvention
{
    public CreationDateConvention(string default)
    {
        _default = default;
    }

    public void Apply(... instance)
    {
        if (instance.Name == "CreationDate")
            instance.Default(_default)
    }
}


// and while configuring
...FluentMappings.AddFromAssemblyOf<>().Conventions.Add(new CreationDateConvention(isOracle ? "to_date..." : Datetime.Minvalue.ToString())
Firo
  • 30,626
  • 4
  • 55
  • 94