Here is my database structure:
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?