following function return List of records
public IList<T> GetAll()
{
return db.TabMasters.ToList<T>();
}
Error:
‘System.Data.Objects.ObjectSet’ does not contain a definition for ‘ToList’ and the best extension method overload ‘System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable)’ has some invalid arguments
IList<T>is the Interface that is used byList<T>and several other similar containers. You can’t return an Interface itself – you have to return an object that implementsIList<T>. Though I don’t know exactly what your situation is, the best choice is most likelyList<T>.Also, you have a problem with the generic Type
T. If you want the method to be generic, then you have to cast all the values indb.TabMastersto Type T. This gets tricky because you’ll have to limit the possible Types used for T to prevent Exceptions caused by an invalid cast (see here). If you only need to return one type, then you should define that as the return type instead of usingT. For example, lets say that all the values indb.TabMastersarestring. Then you’d use:If you really need the method to be generic, then you have to cast the values in db.TabMasters to the type you want to return:
Note that if the object type stored in
db.TabMasterscan’t be cast toT, the method will throw anInvalidCastException.Happy Coding!