Map DateTime as NHibernate.Type.TicksType

Jacob's Avatar

Jacob

16 Oct, 2010 12:48 PM via web

Hi

Is it possible to tell FNH that DateTime should always map to TicksType?

The following is not correct:

    public class DateTimeConvention : IPropertyConvention, IPropertyConventionAcceptance
    {
        public void Apply(IPropertyInstance instance)
        {
            instance.CustomType(typeof(TicksType));
        }

        public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
        {
            criteria.Expect(x => typeof (DateTime).IsAssignableFrom(x.Property.PropertyType));
        }
    }
  1. Support Staff 2 Posted by James Gregory on 16 Oct, 2010 03:44 PM

    James Gregory's Avatar

    Try:

    criteria.Expect(x => x.Property.PropertyType == typeof(DateTime));

    On Sat, Oct 16, 2010 at 1:50 PM, Jacob <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  2. 3 Posted by Jacob on 16 Oct, 2010 09:45 PM

    Jacob's Avatar

    I get this when trying:

    [MappingException: Could not instantiate IType TicksType: System.MissingMethodException: No parameterless constructor defined for this object. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type) in d:\CSharp\NH\nhibernate\src\NHibernate\Bytecode\ActivatorObjectsFactory.cs:line 9 at NHibernate.Type.TypeFactory.HeuristicType(String typeName, IDictionary`2 parameters) in d:\CSharp\NH\nhibernate\src\NHibernate\Type\TypeFactory.cs:line 479]

  3. 4 Posted by Jacob on 16 Oct, 2010 09:52 PM

    Jacob's Avatar

    It works.

    instance.CustomType(typeof(TicksType));
    should be:
    instance.CustomType("Ticks");

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Five times two is what?