Skip to content

EF Core error #3569

@mhamri

Description

@mhamri

repo: https://github.com/mhamri/ef-int32-bug

applying oData queries on top of projected IQueryable throwing error. this was not the case for the older version.

Source/destination types

source:

public class Store
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public int OwnerId { get; set; }
        public Person Owner { get; set; }

        public ICollection<Book> Books { get; set; }
        public ICollection<BookStore> BookStore { get; set; }

    }

destination

public class StoreModel
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public PersonModel Owner { get; set; }

        public ICollection<BookModel> Books { get; set; }
        public IEnumerable<BookStoreModel> BookStore { get; set; }

    }

Mapping configuration

CreateMap<Person, PersonModel>();
CreateMap<Book, BookModel>();
CreateMap<Store, StoreModel>();
CreateMap<BookStore, BookStoreModel>();

Version: 10.1.1

Expected behavior

like the previous version return result!

Actual behavior

throwing error

System.InvalidOperationException: Rewriting child expression from type 'System.Int32' to type 'System.Nullable`1[System.Int32]' is not allowed, because it would change the meaning of the operation. If this is intentional, override 'VisitUnary' and change it to allow this rewrite.

I'm not sure why even there is a nullable value

Steps to reproduce

please check the repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions