Using Visual Studio's O/R Designer, I have created a number of classes the inherit from a base class (named SCO).
The inherited types have a discriminator property TypeId which is a string containing the name of the type. For example, the inherited class Blog would have a TypeId property of Blog.
I want to be able to create a method that returns a strongly typed collection of any of the particular inherited types. My attempt at this method is as follows:
public static IQueryable<T> GetSCOs<T>(SCODataContext dc) where T : SCO
{
string targetType = typeof(T).Name;
IQueryable<T> scos = from s in dc.SCOs
where s.TypeId == targetType
select s;
return scos;
}
When I try and compile this method, I get the following error...
_Cannot implicitly convert type 'System.Linq.IQueryable<SCOs.SCO>' to 'System.Linq.IQueryable<T>'. An explicit conversion exists (are you missing a cast?)_
I (think) I understand why this is happening, but have been unable to find a solution. Any advice, guidance would be much appreciated.
IQueryable<T>in your error message.