NikolayIT / NikolayIT/ASP.NET-Core-Template
Custom AutoMapping in ASP.NET Core as per lecture "Advanced Topics I" gives me unusual error
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 174
- Avg merge
- 7m
- Merged PRs (30d)
- 1
Description
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(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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CarService.cs at GetTopCars and HomeController.cs at Index, then reproduce the custom YearAndMonth mapping scenario described in the lecture. Review the attached Null_TypeMapping.txt stack trace and compare the working automapping case with the failing custom mapping query. Done means identifying the cause of the InvalidOperationException and restoring successful execution of the query.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100