0

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__AnonymousType12 <>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

4
  • 1
    Is the data null in the database? Commented May 22, 2019 at 12:01
  • Can you show the code that causes the error? Commented May 22, 2019 at 12:01
  • 1
    @bvoyelr in db field is not null Commented May 22, 2019 at 12:05
  • @TonyAbrams dbContext.Prices.ToList() Commented May 22, 2019 at 12:08

1 Answer 1

0

I'm sorry, but it was my mistake. We have own EntityMaterializerSource, that works incorrect. I'll close issue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.