I am using Code First Entity Framework.
I am using the following simple classes:
public class Users
{
public ICollection<Projects> Projects{get;set;}
}
public class Projects
{
public ICollection<Users> Users{get;set;}
}
I am using linq for data retrieval. When performing the following query: (Note that lstProjects
is a List<Project>
)
var lstUsers = (from users in lstProjects
where users.ProjectId == pId
select users.Users).ToList();
I have a List<Users>
object and want to populate this List with items. Like,
var lstUsersToDisplay = new List<Users>();
lstUsersToDisplay = (List<Users>)lstUsers; //This can't be cast.
What's the approach to convert ICollection<T>
to List<T>
?
Secondly, I have List<Users>
and want to convert it into ICollection<Users>
how achieve this?
Edited:
Scenario, more clearly is that
All Projects
are loaded in lstProjects
and we need to select the Users
which were mapped to a specific project. These Users are also are contained inside Projects
as collection. Every Project
has its Users collection
like if I decomposed the lstProjects it would be like:
lstProjects --> [0]-->//other Properties
ICollection[Users]-->[0]//Contains User class Properties
[1]....
[1] ... same procedure
Hope it clears the scenario