Base solution for your next web application
Open Closed

Issues Migration AspNetZero .Core MVC/JQuery version 5.5 to version 9.0.1 #9545


User avatar
0
Leonardo.Willrich created

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?

  1. 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.

  1. 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?

  2. 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)