I am doing a migration from AspNetZero MVC/.Core JQuery version 5.5 to version 9.01 and I have found 3 issues that I cannot understand wy and in my point of view it is worst in the previous version. Can someone explain me why it has changed?
- Self-closing tags: Previous, I was able to user self-closing tags for TextArea ans Select.
Before: <select id="create-visit-crew" class="form-control w-100" />
Now: <select id="create-visit-crew" class="form-control w-100"> </select>
This element is used to create a kendo.ui.dropdown, so, I don't need add options on the cshtml file. Using version 9.0.1 if I don't add the close tag it don't close the tag, however, on version 5.5 there is no problem doing that.
Object Mapper: Using version 5.5 some mappings there is no need to configure the map on CustomDtoMapper.cs file. But, on version 9.0.1, I had to configure all mappings objects (most of them are entity to dto). Is there some reason for that?
LINQ queries are not working as before: Some queries simplely doesn't work on the same estruture and are raising an exception suggesting to rewrite the query.
For example, this query:
var visitMaterialsUsedRecords = _materialRepository.GetAll() .Where(m => visitDto.TaskIds.Contains(m.TaskId.Value)) .GroupBy(m => m.MaterialTemplateId.Value) .Select(m => new VisitMaterialsUsed() { VisitId = visitDto.Id.Value, VisitReportId = report.Id, MaterialTemplateId = m.First().MaterialTemplateId.Value, Quantity = m.Sum(mt => mt.Quantity), OriginallyScheduled = true, }).ToList();
It is raising this exeption:
The LINQ expression '(GroupByShaperExpression: KeySelector: (int)(m.MaterialTemplateId), ElementSelector:(EntityShaperExpression: EntityType: Material ValueBufferExpression: (ProjectionBindingExpression: EmptyProjectionMember) IsNullable: False ) ) .First()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
So, I had to rewrite to this:
``var visitMaterialsUsedRecords = _materialRepository.GetAll() .Where(m => visitDto.TaskIds.Contains(m.TaskId.Value)).AsEnumerable();
var visitMaterialsUsed = visitMaterialsUsedRecords.GroupBy(m => m.MaterialTemplateId.Value)
.Select(m => new VisitMaterialsUsed()
{
VisitId = visitDto.Id.Value,
VisitReportId = report.Id,
MaterialTemplateId = m.First().MaterialTemplateId.Value,
Quantity = m.Sum(mt => mt.Quantity),
OriginallyScheduled = true,
}).ToList();``
Can some one explain why it has changed and what is wrong with the previous query?
2 Answer(s)
-
0
Hi @Leonardo.Willrich,
- We haven't do any deployment to prevent this. If you can use this in a regular ASP.NET Core application, it should work in AspNet Zero as well. If you can't figure out the problem, please send your project to [email protected].
- This is related to https://jimmybogard.com/automapper-9-0-released/
- This is related to https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#linq-queries-are-no-longer-evaluated-on-the-client
Thanks,
-
0
Thank you @ismcagdas
Items 2 and 3 are well explained. But, for item 1, it is still a mistery for me. Definitely, there is something different when using template 5.5 and 9.0.1. Maybe it is a parameters in the project that changes the HTML version or something like that. But, any way, as per W3C especification TextArea and Select are not self-closing tags, then we've changed all of them.