我将尝试创建一个通用函数,它接受一个
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;
}
}
接口使我可以访问ID属性
public interface IMatchable
{
int ID { get; set; }
}
我的错误
类型 'T' 必须是引用类型,才能将其用作泛型类型或方法 'System.Data.Linq.Table' 中的参数 'TEntity'
我不确定我的错误在哪里。