Entity framework generic repository

A generic repository class is a class with generic CRUD methods wich can handle your CRUD methods for all you Entity's.Well almost then.

Untill now I have this:

public class Repository<Trepository> where Trepository: ObjectContext, new()

        public event EventHandler DataSaved;

        private Trepository context;

       public Repository()
       {
           context = new Trepository() ;
       }

        public void Add<T>(T entry)
        {
          context.AddObject(entry.GetType().Name + "s", entry);
          context.SaveChanges();
            if (DataSaved != null)
                DataSaved(this,null);
        }

        public void Delete<T>(T entry)
        {
            context.DeleteObject(entry);
            context.SaveChanges();
            if (DataSaved != null)
                DataSaved(this, null );
        }
        
        public Dictionary GetColumnNames<T>(T entity)
        {
            Dictionary columnlist = new Dictionary();
            foreach (var item in entity.GetType().GetProperties())
            {
                columnlist.Add(item.Name, item.PropertyType);
            }

            return columnlist;
        }

         public List Getlist(T entry)where T: class
        {

                return context.CreateObjectSet().ToList();
        }

}

The strange thing is entry.GetType().name+"s". This is because I used the pluralized function which puts an as after the entity's name but the entry.GetType().name returns the object name. Public event DataSaved is used in the business layer to rebuild the cached Lists<> if there are any.

With this Repository base class I don't have to write all the update, delete methods for the different datasources there are. Currently there are three different datasources. In the actual data-class in the datalayer I can put Filter methods wich acceps a predicate to filter the data. This cannot be placed in the Repository class because the Lambda Expression tree doesn't work with Generics.

public class CentraalArtikelBestandData:Repository
{

        public List<CentraalArtikelBestand> FilterCentraalArtikelBestand(Expression<Func<CentraalArtikelBestand, bool>> expr)
        {
            return context.CentraalArtikelBestands.Where(expr).ToList();
        }
}

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!