c# 4.0 - Linq Invalid Cast Exception Same Object Type -


I have written this question and as I have improved my understanding of business rules, I have modified it.

In this most recent visit, I was testing to see that in fact I have some redundancy which can be removed. Let me query you first error.

  Public listing & lt; ExternalForums & gt; GetAllExternalForums (int extforumBoardId) {list & lt; ExternalForums & gt; Xtrnlfrm = new list & lt; ExternalForums & gt; (); Var query = _forumExternalBoardsRepository.Table. Where (id = & gt; id.Id == extoformBoardId). Select (ExtForum = & gt; ExtForum.ExternalForums); Foreign currency (external forum item in query) {xtrnlfrm.Add (new external forum {id = item.id, forum-name = item.forname, forum url = item.form url}); } Return xtrnlfrm; }   

It is not clear now that the query is returning the list of ExternalForums. I then add loop and item to the list of other fororphorphis objects through the list. This is redundancy which was hoping to remove me.

The precompiler was gtg, so I was kosher before re-once again and went as a strange error as I started the loop.

Unable to remove system object. To type Colllections.Generic.HashSet NamSpcA.NamSpcB.ExternalForums, NamSpcA.NamSpcB.ExternalForums

huh? They are the same object type.

Am I doing something wrong in my way of presenting the selection?

TIA

  var query = _forumExternalBoardsRepository.Table. Where (id = & gt; id.Id == extoformBoardId). Select (ExtForum = & gt; ExtForum.ExternalForums);   

This query returns IEnumerable & lt; T & gt; where T is type property, which is expected to be another collection, this time the ExternalForum and the error message Matches that, you have IEnumerable & lt; HashSet & lt; ExternalForums & gt; & Gt; .

If you have a large collection of archive archives <> external forums use SelectMany instead:

  var query = _forumExternalBoardsRepository .Table. Where (id = & gt; id.Id == extoformBoardId). Selection (many) ExtForum = & gt; ExtForum.ExternalForums);    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -