Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace F.DAL
- {
- public class ForumRepository : IForumRepository
- {
- private FContext ctx;
- public ForumRepository()
- {
- ctx = new FContext();
- }
- public void Create<C>(C objectToCreate) where C : class
- {
- ctx.GetSet<C>().Add(objectToCreate);
- ctx.SaveChanges();
- }
- public IEnumerable<C> ReadObjects<C>() where C : class
- {
- return ctx.GetSet<C>().ToList<C>();
- }
- public C Read<C>(int objectId) where C : class
- {
- return ctx.GetSet<C>().Find(objectId);
- }
- public void Delete<C>(int objectId) where C : class
- {
- ctx.GetSet<C>().Remove(ctx.GetSet<C>().Find(objectId));
- ctx.SaveChanges();
- }
- public IEnumerable<D> ReadXFromY<D, C>(int objectId) where C : class, IHasList<object>
- {
- return (IEnumerable<D>)ctx.GetSet<C>().Find(objectId).List;
- }
- public C ReadByName<C>(string objectName) where C : class, IHasUniqueName
- {
- return (C) ctx.GetSet<C>().Single(c => c.Name == objectName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment