Guest User

ForumRepository

a guest
Dec 27th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. namespace F.DAL
  2. {
  3.     public class ForumRepository : IForumRepository
  4.     {
  5.         private FContext ctx;
  6.  
  7.         public ForumRepository()
  8.         {
  9.             ctx = new FContext();
  10.         }
  11.  
  12.         public void Create<C>(C objectToCreate) where C : class
  13.         {
  14.             ctx.GetSet<C>().Add(objectToCreate);
  15.             ctx.SaveChanges();
  16.         }
  17.  
  18.         public IEnumerable<C> ReadObjects<C>() where C : class
  19.         {
  20.             return ctx.GetSet<C>().ToList<C>();
  21.         }
  22.  
  23.         public C Read<C>(int objectId) where C : class
  24.         {
  25.             return ctx.GetSet<C>().Find(objectId);
  26.         }
  27.  
  28.         public void Delete<C>(int objectId) where C : class
  29.         {
  30.             ctx.GetSet<C>().Remove(ctx.GetSet<C>().Find(objectId));
  31.             ctx.SaveChanges();
  32.         }
  33.  
  34.         public IEnumerable<D> ReadXFromY<D, C>(int objectId) where C : class, IHasList<object>
  35.         {
  36.             return (IEnumerable<D>)ctx.GetSet<C>().Find(objectId).List;
  37.         }
  38.  
  39.         public C ReadByName<C>(string objectName) where C : class, IHasUniqueName
  40.         {
  41.             return (C) ctx.GetSet<C>().Single(c => c.Name == objectName);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment