Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate Automapping: Alter DateTime to Timestamp
    primarykey
    data
    text
    <p>I am getting (a little bit to) deep into automapping with the fluent interface of NHibernate. Very nice thing, but I ran into a little problem with DateTimes. I need to change the data format to timestamp, otherwise NHibernate truncates milliseconds.</p> <p>I found several sources of information, the best one was: <a href="http://blog.jagregory.com/2009/01/11/fluent-nhibernate-auto-mapping-type-conventions/" rel="nofollow noreferrer">AutoMapping Info 1</a> where he is changing the column name and type of a property. The problem is, there was a change in the fluent automappings, according to <a href="http://wiki.fluentnhibernate.org/show/diff/ConvertingToNewStyleConventions" rel="nofollow noreferrer">this document</a>.</p> <p>Now I cant figure out how to get the automapping to "change the type". I tried the following code, but I am stuck. Again, what I want to do is simply tell the automapper to: </p> <p><strong>Use Timestamps for DateTime to prevent the truncation of milliseconds when using automapping.</strong></p> <p>Anyone got an idea? Code so far:</p> <pre><code> public class DateTimeToTimestamp : IClassConvention { public bool Accept(IClassMap target) { return target.GetType() == typeof(DateTime); } public void Apply(IClassMap target) { throw new NotImplementedException(); } } </code></pre> <p>Ok, thanks a lot for the answer... Its enough comfort for me that way. If I really have 3 classes which need this precision, I can deal with writing it three times. Especially because the mapping of all other properties works still perfectly, and the following code only alternates the one property I want to... Very nice!</p> <p>If anybody knows a more generic approach, feel free to add it, but for now, I am happy!</p> <p>Code for my case was:</p> <pre><code> public class DateTimeToTimestamp : IAutoMappingOverride&lt;CustomTime&gt; { public void Override(AutoMap&lt;CustomTime&gt; mapping) { mapping.Map(x =&gt; x.ScanDate).CustomTypeIs("timestamp"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload