Muse.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //using System;
  2. //using System.Collections.Generic;
  3. //using System.Linq;
  4. //using System.Linq.Expressions;
  5. //namespace Y.DB.DAO
  6. //{
  7. // public class Muse : IDbContext
  8. // {
  9. // DbTable db;
  10. // public Muse()
  11. // {
  12. // db = new DbTable();
  13. // }
  14. // public int Add<T>(T EntityObj, bool isSave = true) where T : class
  15. // {
  16. // try
  17. // {
  18. // this.db.Set<T>().Add(EntityObj);
  19. // if (isSave)
  20. // {
  21. // return Save();
  22. // }
  23. // }
  24. // catch (Exception e) { }
  25. // return 0;
  26. // }
  27. // public int Adds<T>(IEnumerable<T> EntityObjs) where T : class
  28. // {
  29. // try
  30. // {
  31. // db.Set<T>().AddRange(EntityObjs);
  32. // return Save();
  33. // }
  34. // catch (Exception e) { return 0; }
  35. // }
  36. // public int Del<T>(T EntityObj, bool isSave) where T : class
  37. // {
  38. // try
  39. // {
  40. // this.db.Set<T>().Remove(EntityObj);
  41. // if (isSave)
  42. // {
  43. // return Save();
  44. // }
  45. // }
  46. // catch (Exception e) { }
  47. // return 0;
  48. // }
  49. // public int Dels<T>(IEnumerable<T> EntityObjs) where T : class
  50. // {
  51. // try
  52. // {
  53. // this.db.Set<T>().RemoveRange(EntityObjs);
  54. // return Save();
  55. // }
  56. // catch (Exception e) { }
  57. // return 0;
  58. // }
  59. // public int Update<T>(T EntityObj, bool isSave) where T : class
  60. // {
  61. // try
  62. // {
  63. // this.db.Entry(EntityObj).State = EntityState.Modified;
  64. // if (isSave)
  65. // {
  66. // return Save();
  67. // }
  68. // }
  69. // catch (Exception e) { }
  70. // return 0;
  71. // }
  72. // public int Save()
  73. // {
  74. // return db.SaveChanges();
  75. // }
  76. // public T Get<T>(Expression<Func<T, bool>> expression, string[] include) where T : class
  77. // {
  78. // try
  79. // {
  80. // if (include != null && include.Count() > 0)
  81. // {
  82. // DbQuery<T> query = GetInclude<T>(include);
  83. // if (query != null)
  84. // return query.FirstOrDefault(expression);
  85. // }
  86. // return this.db.Set<T>().FirstOrDefault(expression);
  87. // }
  88. // catch (Exception e)
  89. // {
  90. // }
  91. // return null;
  92. // }
  93. // public IEnumerable<T> Gets<T>(Expression<Func<T, bool>> expression, string[] include) where T : class
  94. // {
  95. // try
  96. // {
  97. // if (include != null && include.Count() > 0)
  98. // {
  99. // DbQuery<T> query = GetInclude<T>(include);
  100. // if (query != null)
  101. // return query.Where(expression).ToList();
  102. // }
  103. // }
  104. // catch (Exception)
  105. // {
  106. // throw;
  107. // }
  108. // return db.Set<T>().Where(expression).ToList();
  109. // }
  110. // public IEnumerable<T> GetAll<T>(string[] include, bool track) where T : class
  111. // {
  112. // if (include != null && include.Count() > 0)
  113. // {
  114. // DbQuery<T> query = GetInclude<T>(include);
  115. // if (query != null)
  116. // if (track)
  117. // return query.ToList();
  118. // else
  119. // return query.AsNoTracking().ToList();
  120. // }
  121. // if (!track)
  122. // db.Set<T>().AsNoTracking().ToList();
  123. // return db.Set<T>().ToList();
  124. // }
  125. // private DbQuery<T> GetInclude<T>(string[] include) where T : class
  126. // {
  127. // DbQuery<T> searchCondition = null;
  128. // foreach (var item in include)
  129. // {
  130. // if (searchCondition == null)
  131. // searchCondition = this.db.Set<T>().Include(item);
  132. // else
  133. // searchCondition = searchCondition.Include(item);
  134. // }
  135. // return searchCondition;
  136. // }
  137. // public bool Any<T>(Expression<Func<T, bool>> expression, string[] include) where T : class
  138. // {
  139. // try
  140. // {
  141. // if (include != null && include.Count() > 0)
  142. // {
  143. // DbQuery<T> query = GetInclude<T>(include);
  144. // if (query != null)
  145. // return query.Any(expression);
  146. // }
  147. // return this.db.Set<T>().Any(expression);
  148. // }
  149. // catch (Exception e)
  150. // {
  151. // }
  152. // return false;
  153. // }
  154. // public DbSet<T> Do<T>() where T : class
  155. // {
  156. // return db.Set<T>();
  157. // }
  158. // public IEnumerable<T> ExecuteSqlCom<T, U>(string sql, U paramObjs)
  159. // where U : class
  160. // where T : class
  161. // {
  162. // return db.Set<T>().SqlQuery(sql, paramObjs);
  163. // }
  164. // public void Dispose()
  165. // {
  166. // db.Dispose();
  167. // }
  168. // }
  169. //}