Hello everyone,
I am converting some programs (WebApi) to dontnet core 3.1, Oracle 12 and Oracle.EntityFrameworkCore version 5.21.1.
I'm having trouble handling null datetime.
In the program excerpt below I tried the ways in italics but the result was always the same, that is, the bold line causes an exception:
UsuarioDbContext ctx = new UsuarioDbContext(Globais.GetConnStr());
DateTime data = DateTime.Now.Date;
try
{
var query = (from jaf in ctx.jafs
where jaf.JAF\_DTINICIO.Date \<= data
select new
{
inicio = jaf.JAF\_DTINICIO.ToString("dd/MM/yyyy"),
_//fim = jaf.JAF\_DTFIM.ToString("dd/MM/yyyy" ),_
_//fim = (jaf.JAF\_DTFIM.Equals(DBNull.Value) ? new DateTime(1900, 01, 01) : jaf.JAF\_DTFIM),_
_fim = (jaf.JAF\_DTFIM == null ? new DateTime(1900, 01, 01) : jaf.JAF\_DTFIM),_
unidade = jaf.UNI\_IDUNIDADE
}
);
string sqlstr = query.ToQueryString();
**var lst = await query.ToListAsync();**
return await query.ToArrayAsync();
}
catch (System.Exception exc)
The exception trace is:
Exception has occurred: CLR/System.InvalidOperationException
Exceção gerada: 'System.InvalidOperationException' em System.Private.CoreLib.dll: 'Nullable object must have a value.'
em System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_NoValue()
em Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.<MoveNextAsync>d__14.MoveNext()
em System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
em Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__65`1.MoveNext()
em System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
em Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__65`1.MoveNext()
em System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
em System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
em siges_api.Repository.UsuarioRepository.<GetUsuarioAsync>d__3.MoveNext() em C:\Desenv\C#\PMS\siges-api\Repository\UsuarioRepository.cs:linha 135
Any help is welcome