I have ef core (on Postgres) model
public class Price
{
public Price()
{
}
public string OrderId { get; set; }
public string Currency { get; set; }
public decimal Amount { get; set; }
public string Message { get; set; }
public PriceType PriceType { get; set; } // enum
public DateTime SyncingOn { get; set; }
[ConcurrencyCheck]
public DateTimeOffset UpdatedOn { get; set; }
}
modelBuilder.Entity<Price>(z =>
{
z.ToTable(nameof(Price));
z.HasKey(p => p.OrderId);
z.Property(p => p.PriceType)
.IsRequired()
.HasConversion(v => v.ToString(),
v => (PriceType)Enum.Parse(typeof(PriceType), v));
});
This model has one field with DateTime type. If I try to select that field, then EF throw exception
dbContext.Prices.ToList()
System.ArgumentNullException: Value cannot be null. Parameter name: method at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0) at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityMaterializerSource.<>c__DisplayClass7_0.b__2(<>f__AnonymousType1
2 <>h__TransparentIdentifier0) at System.Linq.Utilities.<>c__DisplayClass2_03.b__0(TSource x) at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 enumerable) at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityMaterializerSource.CreateMaterializeExpression(IEntityType entityType, Expression materializationExpression, Int32[] indexMap) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MaterializerFactory.CreateMaterializer(IEntityType entityType, SelectExpression selectExpression, Func3 projectionAdder, Dictionary2& typeIndexMap) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.CreateShaper(Type elementType, IEntityType entityType, SelectExpression selectExpression) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitEntityQueryable(Type elementType) at System.Linq.Expressions.ConstantExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause, QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable1.System.Collections.Generic.IAsyncEnumerable<TResult>.GetEnumerator() at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable1 source, TAccumulate seed, Func3 accumulator, Func2 resultSelector, CancellationToken cancellationToken)
If I change DateTime to DateTimeOffset it works fine