0

Here is my database structure:

enter image description here

I am using Linq-to-SQL, here is my class structure.

 DataBaseClassDataContext context = new DataBaseClassDataContext();
 GenericMethod gm = new GenericMethod();
 var student= gm.GetData<info>(1);
 var info = gm.GetData<Student>(2);
 Console.ReadLine();

Here is my GenericMethod class:

DataBaseClassDataContext context = new DataBaseClassDataContext();

public List<T> GetData<T>(int classcode) 
{
    if (classcode == 1)
    {
         return context.InfoSelect().Cast<T>().ToList<T>();
    }
    else
    {
        return context.StudentSelect().Cast<T>().ToList<T>();
    }
}

I want to pass class to my generic method, which further run stored procedure and give back me list of that class. How can I do that? I get an error

Unable to cast object of type 'GenericMethods.StudentSelectResult' to type 'GenericMethods.Student'.

Kindly guide me, what am I missing?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Muhammad Ali
  • 853
  • 1
  • 10
  • 18

0 Answers0