Search code examples
c#entity-framework-4entitycollection

EntityCollection as parameter in a method


I am trying to write a code where EntityCollection is the parameter of the method but I don't know what is the proper coding

is there someone who can help me about this?

here is the sample code

 //by the way, this is a wrong coding, I am just showing you, what is the thing that I want to do...
private void sampleMethod(EntityCollection a)
{
   if (a.ToList().Count == 0)
   {
      //body
   }
}

and when I call it, this is what it looks like

sampleMethod(employee.EducationalBackground);

Solution

  • The question is a little difficult to understand but I suppose you're looking for something like this:

    private void sampleMethod(EntityCollection<Employee> employees)
    {
       foreach(var employee in employees)
       {
          // do something with every employee.EducationalBackground
       }
    }
    

    Search for "c# Generics" for info about the EntityCollection<Employee>.

    Search for "linq" for info about how to work with collections.