I am trying to run this code:
ItemTaxonomy iTaxonomy = from itemTaxonomy in connection.ItemTaxonomy
where itemTaxonomy.Item.ID == itemView.ID
orderby itemTaxonomy.Taxonomy.Name
select itemTaxonomy;
When I compiled it I get the error:
Cannot implicitly convert type
'System.Linq.IOrderedQueryable<Website.Models.ItemTaxonomy>'to
'Website.Models.ItemTaxonomy'. An explicit conversion exists (are you missing a cast?)
I believe the issue is with orderby itemTaxonomy.Taxonomy.Name but I am just trying to order by the name of Taxonomy items instead of their IDs. Is there a way to do that?
No, the problem is that the result is a sequence whereas your variable is a single item.
Given that you’re expressing ordering, you must be expecting multiple values – so what do you want to do with them? Options:
Use
First():This will return the
ItemTaxonomywith the earliest name out of all the ones with the appropriate item ID.Change your variable type:
Now you’ve got a sequence of taxonomies to deal with, instead of a single item.