У меня есть модель ядра ef (на Postgres)
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));
});
Эта модель имеет одно поле с типом DateTime.Если я пытаюсь выбрать это поле, то EF выдает исключение
dbContext.Prices.ToList()
System.ArgumentNullException: значение не может быть нулевым.Имя параметра: метод в System.Linq.Expressions.Expression.Call (метод MethodInfo, выражение arg0) в Microsoft.EntityFrameworkCore.Metadata.Internal.EntityMaterializerSource. <> C__DisplayClass7_0.b__2 (<> f__AnonymousType1 * 1008) в System.Linq.Enumerable.SelectEnumerableIterator 2.MoveNext()
at System.Collections.Generic.List
1.AddEnumerable (IEnumerable 1 enumerable)
at System.Collections.Generic.List
1.InsertRange (индекс Int32, IEnumerable 1 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, Func
3 projectionAdder, компилятор словаря 2& 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, Func
1) в Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync [TResult] (запрос выражения) в Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable 1.System.Collections.Generic.IAsyncEnumerable<TResult>.GetEnumerator()
at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable
1 источник, TAccumulate seed, Func 3 accumulator, Func
2 resultSelector, CancellationToken cancellationToken)
* 1017измените DateTime на DateTimeOffset, он работает нормально