Solved

Selecting EntityCollection into collection using LINQ

Posted on 2010-11-20
4
1,824 Views
Last Modified: 2012-05-10
I am trying to select a collection of entities into a custom class using the following code:

 
Public Function GetKeywordSummaries(ByVal _Keywords As EntityCollection(Of Keyword)) As System.Linq.IQueryable(Of KeywordSummary)



            Return (From k In _Keywords _

                        Order By k.Word _

                        Select New KeywordSummary With { _

                           .Id = k.Id, _

                           .Word = k.Word, _

                           .ArticleCount = k.Articles.Count})



        End Function

Open in new window


In the code, I have an entitycollection named Keywords and a custom class KeywordSummaries.

When executing the function, the following error occurs:

 
Unable to cast object of type 'WhereSelectEnumerableIterator`2[Pipeline.Blogjammer.Keyword,Pipeline.Blogjammer.KeywordSummary]' to type 'System.Linq.IQueryable`1[Pipeline.Blogjammer.KeywordSummary]'

Open in new window


Does anyone know why and how to get around this problem?
0
Comment
Question by:pipelineconsulting
  • 3
4 Comments
 
LVL 16

Expert Comment

by:BurnieP
Comment Utility
I'm not sure, maybe you need to specify what type you are returning.  Gave you an example.

Public Function GetKeywordSummaries(_Keywords As EntityCollection(Of Keyword)) As System.Linq.IQueryable(Of KeywordSummary)



	Return (From k In _Keywords

                 Order By k.Word 

                 Select New KeywordSummary With { _

		 .Id = k.Id, _

		 .Word = k.Word, _

		 .ArticleCount = k.Articles.Count }).[Single](Of System.Linq.IQueryable(Of KeywordSummary))



End Function

Open in new window

0
 

Author Comment

by:pipelineconsulting
Comment Utility
This doesn't seem to work.  I am getting an IntelliSense error in Visual Studio:

"Overload Resolution failed because no accessible 'Single' accepts this number of type arguments"
0
 

Accepted Solution

by:
pipelineconsulting earned 0 total points
Comment Utility
I seem to have solved the problem myself by adding .AsQueryable at the end of the LINQ statement
0
 

Author Closing Comment

by:pipelineconsulting
Comment Utility
Problem solved by myself after checking on MSDN
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now