Hello,
we are currently using the Entity Framework 3.1.11 and
facing an error while retrieving a field of type DATE in our Oracle Database
(Version Oracle Database 11g Release 11.2.0.4.0 - 64bit Production) .
The Problem is that in the DB some of the Dates have
as year the value 0 (zero) and .NET can't convert a Date like 01.01.0000 to
System.DateTime because the smallest available Date in .NET is 01.01.0001 which
leads the programm to throw the Error
- System.ArgumentOutOfRangeException: Year, Month, and
Day parameters describe an un-representable DateTime -
To reproduce a DB entry with the year zero I used in
sqlplus the following statement:
update patient set birthday = date'0000-01-05' where
patient_id = 4; (or an insert with " date'0000-01-05'")
Does
someone knows how we could handle the DB entries with year zero dates that a
request to get all patients wouldn't fail because he can't convert one entry to
it's model?
The year zero shouldn't be valid in Oracle but it can be inserted into a date field. This article from 2008 is about the problem with the year zero and gives more examples http://rwijk.blogspot.com/2008/10/year-zero.html
The error message and stacktrace produced in a UnitTest is:
Message:
Test method GetByIdTest threw exception:
System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
Stack Trace:
DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
DateTime.ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond)
DateTimeConv.ToDateTime(Byte[] byteRep, Boolean isNotTimeStampTZ, Int32 offset, Int32 length)
OracleDataReader.GetDateTime(Int32 i)
lambda_method(Closure , QueryContext , DbDataReader , ResultContext , Int32[] , ResultCoordinator )
Enumerator.MoveNext()
Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
PatientDataAccess.Get(Int64 id, Boolean includeChildren) line 92
PatientDataAccessTest.GetByIdTest() line 306
but when i catch the error with a "try - catch" block and lookup the stacktrace inside the exception it's a different one but the difference should be that we have more Information where the OracleDateReader is to find but anyways:
at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond)
at Oracle.ManagedDataAccess.Types.DateTimeConv.ToDateTime(Byte[] byteRep, Boolean isNotTimeStampTZ, Int32 offset, Int32 length)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDateTime(Int32 i)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
at CGM.Arztsysteme.M1X.DataAccess.EFDataAccess.PatientDataAccess.Get(Int64 id, Boolean includeChildren) in ...
This is my first question here and I hope that my problem is good explained and someone has a solution for me. Anyways thank you for reading my question.
If some Information is missing I will try to add them as fast as possible.
Thank you very much,
~ Jan