S
S
Sergey Melnikov2020-01-18 18:15:38
ASP.NET
Sergey Melnikov, 2020-01-18 18:15:38

How to overcome the conversion error?

var i = SectionRepository.GetAll().OrderBy(x => x.Name).GroupBy(x => x.Category).OrderBy(x => x.Key.Name);
 var b = (IOrderedEnumerable<IGrouping<TaggedEntity, TaggedEntity>>)i;

Hello. Tell. Section and Category are inherited from TaggedEntity. An error occurs while converting.
.net 4 is used in the project. How can you convert?
Unable to cast object of type 'System.Linq.OrderedEnumerable`2[System.Linq.IGrouping`2[Prj.Core.Domain.Category,Prj.Core.Domain.Section],System.String]' to type 'System. Linq.IOrderedEnumerable`1[System.Linq.IGrouping`2[Prj.Core.Common.TaggedEntity,Prj.Core.Common.TaggedEntity]]'.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eRKa, 2020-01-18
@kttotto

In your case, i is a pending complex query/select that has not yet been executed. You are trying to convert it to another type. Try it, just in case, first close ToList() and then convert it either via Select or Cast. In principle, if there is nothing complicated inside the request, then you can not do ToList().

R
Roman, 2020-01-19
@yarosroman

You have in the first line type
which is not exactly what you're getting at.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question