views:

23

answers:

1

I Have 3 entities.
Product
LangID
ProductName

Category
LangID
CatName

ProductType
LangID
TypeName

As 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 ???.

+1  A: 

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
Jordan
Where I put the GetLmbLang() Method.. In the repository ????.
Jean-Francois
NICEEE. thats working.
Jean-Francois
@Jean Same place as you had put it I suppose, inside BaseRepository<T>.
Jordan