Passing System.Data.Linq.Table <T> to a generic function
I am trying to create a generic function that accepts System.Data.Linq.Table<T> .
General function
public int Get<T>(MyDataContext db, System.Data.Linq.Table<T> table, string PropertyValue) where T: IMatchable { T prop = table.FirstOrDefault<T>(p => p.Name.ToLower() == PropertyValue.ToLower()); if (prop != null) { return prop.ID; } } Interface so that I can access the ID property
public interface IMatchable { int ID { get; set; } } My mistake
Type "T" must be a reference type in order to use it as the "TEntity" parameter in the generic type or the 'System.Data.Linq.Table' method
I'm not sure what I'm doing wrong.
+6
Jason
source share1 answer
Try specifying where T: class, IMatchable
Since System.Data.Linq.Table has a restriction where TEntity : class you need to make sure that T also a reference type.
+6
The scrum meister
source share