In my ASP.NET Core v2.1 app I have the following:
// beginDate and endDate are .NET DateTime types
var beginDateParam = new NpgsqlDate(beginDate);
var endDateParam = new NpgsqlDate(endDate);
var result = await _reportDb.ReportRows
.FromSql(
"SELECT * FROM \"fnReport\"(@p0, @p1);",
new object[] { beginDateParam, endDateParam
})
.AsNoTracking().ToListAsync();
fnReport function's parameters are of PostgreSQL date type. Before, Npgsql v2.1 the above code used to work. Now, after upgrade it throws an error: "No mapping to a relational type can be found for the CLR type 'NpgsqlDate'".
Without NpgsqlDate, the error will be: " function fnReport(timestamp without time zone, timestamp without time zone) does not exist".
I know that recommended approach is to use NodaTime library. But, using NodaTime library requires a lot of code change (see this issue).
Since, my datetime requirements are quite basic, I can change fnReport's argument types to timestamp data type, and it will work.
However, I have an entity with the following property:
[Column(TypeName = "date")]
[DataType(DataType.Date)]
public DateTime EntryDate { get; set; }
And, for this entity, CRUD operations work fine. My question is, why Npgsql/EF Core is able to do that, but fails to execute a function with date type parameters?