Can't get full missing interval in Oracle

I have a column in Oracle DB:

INTERVAL DAY (0) TO SECOND (6)

      

My model:

public class IntervalTest
{
    public virtual int Id { get; set; }
    public virtual TimeSpan IntervalField { get; set; }
}

      

Fluent ModelMap:

public class IntervalTestMap : ClassMap<IntervalTest>
{
    public IntervalTestMap()
    {
        Table("INTERVALTESTTWO");
        Id(x => x.Id);
        Map(x => x.IntervalField, "IFTest");
    }
}

      

When I ran

criteria.List<T>();

      

I am getting the following exception:

{"query failed \ r \ n [SELECT this_.Id as Id2_0_, this_.IFTest as IFTest2_0_ FROM INTERVALTESTTWO this _] \ r \ n [SQL: SELECT this_.Id as Id2_0_, this_.IFTest as IFTest2_0_ FROM INTERVALTESTTEST ] "}

With InnerException Of:

{"ORA-00904: \" THIS is _ \ ". \" IFTEST \ ": Invalid identifier"}

NHibernate works for all my other models, only with bins field, I get this exception. I have tried changing the column names in case this is a problem to no avail.

Thanks in advance if anyone managed to get an interval type working in Fluent NHibernate with Oracle DB and can help me.

EDIT

solvable; Adding

.Type<NHibernate.Type.TimeAsTimeSpanType>();

      

By mapping, it worked. Thanks Radmin (answer below)!

+3


source to share


1 answer


Not really sure about Oracle ... but as the doc says:

5.2.2. Basic value types

C # TimeSpan maps to . And that's not what we want. DbType.Int64

Solution: TimeAsTimeSpanType

We can use this free mapping:

Map(c => c.IntervalField, "IFTest")
   .Type<NHibernate.Type.TimeAsTimeSpanType>();

      



See: TimeAsTimeSpanType.cs

/// <summary>
/// Maps a <see cref="System.TimeSpan" /> Property to an 
/// <see cref="DbType.Time" /> column
/// This is an extra way to map a <see cref="DbType.Time"/>. You already have 
/// <see cref="TimeType"/>
/// but mapping against a <see cref="DateTime"/>.
/// </summary>
[Serializable]
public class TimeAsTimeSpanType : PrimitiveType, IVersionType

      

You can learn more about this here: Working with time type in Fluent Nhibernate throws the exception "Cannot overlay object of type 'System.DateTime' on type 'NHibernate.Type.TimeType";

Also, I would suggest trying to avoid the column name. SQL Server is running "[ColumnName]". I guess in general, including Oracle, this works

Map(x => x.IntervalField, "`IFTest`");

      

+1


source







All Articles