I Have 3 entities.
Product LangID ProductName Category LangID CatName ProductType LangID TypeNameAs you can see, each of them has LangID Property.
I Would like be able to create a generic repository 开发者_运维知识库that will contain only one function that will return an Func<T, bool> GetLmbLang()
public interface IBaseRepository<T> where T : class
{
Func<T, bool> GetLmbLang();
}
public class BaseRepository<T> : IBaseRepository<T> where T : class
{
public Func<T, bool> GetLmbLang()
{
//ERROR HERE
//That dosen't work here
return (p => p.LangID == 1);
}
}
Someone has an idea ???.
One way you can accomplish this is by creating an interface with the LangID property, and have each of your classes implement this.
public interface IHasLangID
{
string LangID { get; set; }
}
public class Product : IHasLangID
...
public class Category : IHasLangID
...
public class ProductType : IHasLangID
...
public interface IBaseRepository<T> where T : IHasLangID
...
public class BaseRepository<T> : IBaseRepository<T> where T : IHasLangID
精彩评论