I'm trying to make a generic function that takes in a System.Data.Linq.Table<T>
.
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;
}
}
public interface IMatchable
{
int ID { get; set; }
}
The type 'T' must be a reference type in order to use it as parameter 'TEntity' in the generic type or method 'System.Data.Linq.Table'
I'm not sure what I am doing wrong.
Try specifying where T: class, IMatchable
Since the System.Data.Linq.Table
has a constraint where TEntity : class
You need to make sure that T
is also a reference type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With