Guest User

Untitled

a guest
Feb 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Objects;
  4. using System.Data.Objects.DataClasses;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace SupplierManual.Data
  9. {
  10.     public class Repository :IRepository
  11.     {
  12.         private SupplierManualEntities objectContext;
  13.  
  14.         public Repository()
  15.         {
  16.             objectContext = new SupplierManualEntities();
  17.         }
  18.  
  19.         public IQueryable<TEntity> Queriable<TEntity>() where TEntity : class
  20.         {
  21.             Type baseType;
  22.             if (HasBaseType(typeof(TEntity), out baseType))
  23.             {
  24.                 return this.objectContext.CreateQuery<TEntity>(String.Format("[{0}]", baseType.Name.ToString())).OfType<TEntity>();
  25.             }
  26.             else
  27.             {
  28.                 return this.objectContext.CreateQuery<TEntity>(String.Format("[{0}]", typeof(TEntity).Name.ToString()));
  29.             }
  30.         }
  31.  
  32.         public void Add<TEntity>(TEntity entity) where TEntity : class
  33.         {
  34.             throw new NotImplementedException();
  35.         }
  36.  
  37.         public void Update<TEntity>(TEntity entity) where TEntity : class
  38.         {
  39.             throw new NotImplementedException();
  40.         }
  41.  
  42.         public void Delete<TEntity>(TEntity entity) where TEntity : class
  43.         {
  44.             throw new NotImplementedException();
  45.         }
  46.  
  47.         public void Dispose()
  48.         {
  49.             throw new NotImplementedException();
  50.         }
  51.  
  52.         public void SaveChange()
  53.         {
  54.             throw new NotImplementedException();
  55.         }
  56.  
  57.         private bool HasBaseType(Type type, out Type baseType)
  58.         {
  59.             Type originalType = type.GetType();
  60.             baseType = GetBaseType(type);
  61.             return baseType != originalType;
  62.         }
  63.  
  64.         private static Type GetBaseType(Type type)
  65.         {
  66.             Type baseType = type.BaseType;
  67.             if (baseType != null && baseType != typeof(EntityObject))
  68.             {
  69.                 return GetBaseType(type.BaseType);
  70.             }
  71.             return type;
  72.         }
  73.  
  74.     }
  75.  
  76. }
Add Comment
Please, Sign In to add comment