ASP.NET-Core-Template icon indicating copy to clipboard operation
ASP.NET-Core-Template copied to clipboard

Custom AutoMapping in ASP.NET Core as per lecture "Advanced Topics I" gives me unusual error

Open bodyquest opened this issue 5 years ago • 0 comments

Hi Niki,

Despite doing exactly as in the lecture about the AudiCars and the custom mapped property "YearAndMonth", I get a rare error which I can't even solve from SOF or Google.

It is : InvalidOperationException: Null TypeMapping in Sql Tree I tried also to remove the sorting from the LINQ Query in case something with my dates is not ok, but problem remains

Here is where it happens. The BOLD lines of code are marked where error happens. I attached a full copy of the stack to this issue

`RPM.Services.Data.Cars.CarService.GetTopCars<TViewModel>(int count) in CarService.cs

        {
            this.context = context;
        }
        public IEnumerable<TViewModel> GetTopCars<TViewModel>(int count = 2)
        {
            **var cars = this.context.Cars**
                .OrderByDescending(x => x.CreatedOn)
                .Take(count)
                .To<TViewModel>()
                .ToList();
            return cars;

RPM.Web.Controllers.HomeController.Index() in HomeController.cs

        {
            this.carsService = carsService;
        }
        public IActionResult Index()
        {
            **var cars = this.carsService.GetTopCars<HomePageCarViewModel>(2);**

            return this.View(cars);
        }
        public IActionResult Privacy()
        {
            return this.View();

` You successfully demonstrated how it happens. I just need a clue what could cause this on my side.. I also created manually 2 Cars and several CarModels from MSSMS and this is how I was replicating what you demonstrated. But with no success. Side note: It works on my side as per your demonstration with the automapping up until the custom mapping example.

Null_TypeMapping.txt

bodyquest avatar Feb 08 '20 12:02 bodyquest