Fluent Nhiberhate And Missing Milliseconds

前端 未结 1 2100
旧时难觅i
旧时难觅i 2021-02-13 07:34

I am using Fluent Nhibernate and Nhibernate for my current project. I need to record the time to the millisecond. I have this for my mapping

            Map(x          


        
1条回答
  •  生来不讨喜
    2021-02-13 07:53

    We use the same approach as you and it does correctly store the milliseconds. If you weren't always doing it that way though your old records will have lost their milliseconds.

    Assuming you want to store milliseconds for all of your DateTime fields, you could use a convention:

    public class OurPropertyConventions : IPropertyConvention
    {
        public void Apply(IPropertyInstance instance)
        {
            Type type = instance.Property.PropertyType;
            if (type == typeof(DateTime) || type == typeof(DateTime?))
                instance.CustomType("Timestamp");
        }
    }
    

    Your mappings can now just be:

    Map(x => x.SystemDateTime).Not.Nullable();
    

    0 讨论(0)
提交回复
热议问题