PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/EFTester/Acme.TestModel/Business/Views/CustomViewCollection.Generated.cs

#
C# | 1340 lines | 941 code | 111 blank | 288 comment | 169 complexity | 0f0506e2b84e8613f86d63d62590d2b9 MD5 | raw file
Possible License(s): JSON, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Linq;
  3. using System.Data;
  4. using System.Xml;
  5. using System.Collections.Generic;
  6. using System.Collections;
  7. using System.Runtime.Serialization;
  8. using System.ComponentModel;
  9. using Acme.TestModel.Business.Rules;
  10. using Acme.TestModel.Business.SelectCommands;
  11. using Acme.TestModel.Domain.Objects;
  12. using Acme.TestModel.Domain.Views;
  13. using Widgetsphere.Core.DataAccess;
  14. using Widgetsphere.Core.Util;
  15. using Widgetsphere.Core.Logging;
  16. using Widgetsphere.Core.Exceptions;
  17. using System.IO;
  18. using System.Linq.Expressions;
  19. using Acme.TestModel.Business.Objects;
  20. using System.Data.Linq;
  21. using Acme.TestModel.Business.LINQ;
  22. using System.Text.RegularExpressions;
  23. using System.Text;
  24. namespace Acme.TestModel.Business.Views
  25. {
  26. /// <summary>
  27. /// The class representing the 'CustomView' virtual database table
  28. /// </summary>
  29. [Serializable()]
  30. public partial class CustomViewCollection : Widgetsphere.Core.DataAccess.BusinessCollectionBase, Widgetsphere.Core.DataAccess.IReadOnlyBusinessCollection, System.Collections.Generic.IEnumerable<CustomView>, System.ComponentModel.IListSource, System.Collections.IList
  31. {
  32. #region Member Variables
  33. internal DomainCustomViewCollection wrappedClass;
  34. #endregion
  35. #region Constructor / Initialize
  36. internal CustomViewCollection(DomainCustomViewCollection classToWrap)
  37. {
  38. wrappedClass = classToWrap;
  39. }
  40. /// <summary>
  41. /// The default constructor
  42. /// </summary>
  43. public CustomViewCollection()
  44. {
  45. var sd = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  46. wrappedClass = (DomainCustomViewCollection)sd.GetDomainCollection(Collections.CustomViewCollection);
  47. }
  48. #endregion
  49. #region Property Implementations
  50. /// <summary>
  51. /// Returns the internal object that this object wraps
  52. /// </summary>
  53. [System.ComponentModel.Browsable(false)]
  54. public object WrappedClass
  55. {
  56. get { return wrappedClass; }
  57. set { wrappedClass = (DomainCustomViewCollection)value; }
  58. }
  59. /// <summary>
  60. /// A reference to the SubDomain that holds this collection
  61. /// </summary>
  62. public SubDomain SubDomain
  63. {
  64. get
  65. {
  66. try
  67. {
  68. return wrappedClass.SubDomain;
  69. }
  70. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  71. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  72. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  73. }
  74. }
  75. /// <summary>
  76. /// Returns the number of items in this collection
  77. /// </summary>
  78. public override int Count
  79. {
  80. get
  81. {
  82. try
  83. {
  84. DataTable dt = wrappedClass.GetChanges(DataRowState.Deleted);
  85. if (dt == null)
  86. return wrappedClass.Count;
  87. else
  88. return wrappedClass.Count - dt.Rows.Count;
  89. }
  90. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  91. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  92. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  93. }
  94. }
  95. /// <summary>
  96. /// Determines the type of object contained by this collection.
  97. /// </summary>
  98. public Type ContainedType
  99. {
  100. get { return typeof(Acme.TestModel.Business.Views.CustomView); }
  101. }
  102. /// <summary>
  103. /// Determines the type of collection for this object.
  104. /// </summary>
  105. public Collections Collection
  106. {
  107. get { return Collections.CustomViewCollection; }
  108. }
  109. #endregion
  110. #region Enumerator
  111. /// <summary>
  112. /// Gets or sets the element at the specified index.
  113. /// </summary>
  114. /// <param name="index">The zero-based index of the element to get or set. </param>
  115. /// <returns>The element at the specified index.</returns>
  116. public CustomView this[int index]
  117. {
  118. get
  119. {
  120. try
  121. {
  122. var internalEnumerator = this.GetEnumerator();
  123. internalEnumerator.Reset();
  124. int ii = -1;
  125. while(ii < index)
  126. {
  127. internalEnumerator.MoveNext();
  128. ii++;
  129. }
  130. var retval = (CustomView)internalEnumerator.Current;
  131. if (retval.wrappedClass == null)
  132. {
  133. if (!((0 <= index) && (index < this.Count)))
  134. throw new IndexOutOfRangeException();
  135. else
  136. throw new Exception("The item is null. This is not a valid state.");
  137. }
  138. else return (CustomView)internalEnumerator.Current;
  139. }
  140. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  141. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  142. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  143. }
  144. }
  145. #endregion
  146. #region Methods
  147. /// <summary>
  148. /// Create a new object to later add to this collection
  149. /// </summary>
  150. internal CustomView NewItem()
  151. {
  152. try
  153. {
  154. lock (wrappedClass.SubDomain)
  155. {
  156. return new CustomView(wrappedClass.NewItem());
  157. }
  158. }
  159. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  160. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  161. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  162. }
  163. /// <summary>
  164. /// Add a newly created entity to this collection.
  165. /// </summary>
  166. internal virtual void AddItem(CustomView item)
  167. {
  168. try
  169. {
  170. lock (wrappedClass.SubDomain)
  171. {
  172. wrappedClass.AddItem((DomainCustomView)item.WrappedClass);
  173. }
  174. }
  175. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  176. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  177. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  178. }
  179. /// <summary>
  180. /// Execute the cached select commands
  181. /// </summary>
  182. public static CustomViewCollection RunSelect()
  183. {
  184. try
  185. {
  186. var returnVal = new CustomViewCollection(DomainCustomViewCollection.RunSelect());
  187. return returnVal;
  188. }
  189. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  190. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  191. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  192. }
  193. /// <summary>
  194. /// Using the specified Where expression, execute a query against the database to return a result set
  195. /// </summary>
  196. /// <param name="where">The expression that determines the records selected</param>
  197. public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where)
  198. {
  199. return RunSelect(where, new QueryOptimizer());
  200. }
  201. /// <summary>
  202. /// Using the specified Where expression, execute a query against the database to return a paged result set
  203. /// </summary>
  204. public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where, CustomViewPaging paging)
  205. {
  206. return RunSelect(where, paging, new QueryOptimizer());
  207. }
  208. /// <summary>
  209. /// Using the specified Where expression, execute a query against the database to return a paged result set
  210. /// </summary>
  211. public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where, CustomViewPaging paging, QueryOptimizer optimizer)
  212. {
  213. if (paging == null) throw new Exception("The paging object cannot be null.");
  214. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  215. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  216. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  217. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  218. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  219. var parser = LinqSQLParser.Create(cmd.CommandText, paging, LinqSQLParser.ObjectTypeConstants.View);
  220. cmd.CommandText = parser.GetSQL(optimizer);
  221. dc.Connection.Open();
  222. var startTime = DateTime.Now;
  223. var result = dc.Translate<CustomViewQuery>(cmd.ExecuteReader());
  224. var endTime = DateTime.Now;
  225. optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
  226. CustomViewCollection retval = subDomain.GetCollection<CustomViewCollection>();
  227. foreach (var item in result)
  228. {
  229. var newItem = retval.NewItem();
  230. LoadDataRow(item, newItem);
  231. retval.AddItem(newItem);
  232. }
  233. retval.wrappedClass.AcceptChanges();
  234. retval.wrappedClass.EndLoadData();
  235. dc.Connection.Close();
  236. paging.RecordCount = GetCount(where);
  237. return retval;
  238. }
  239. /// <summary>
  240. /// Using the specified Where expression, execute a query against the database to return a result set
  241. /// </summary>
  242. /// <param name="where">The expression that determines the records selected</param>
  243. /// <param name="optimizer">The optimization object</param>
  244. public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  245. {
  246. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  247. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  248. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  249. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  250. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  251. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  252. cmd.CommandText = parser.GetSQL(optimizer);
  253. dc.Connection.Open();
  254. var startTime = DateTime.Now;
  255. var result = dc.Translate<CustomViewQuery>(cmd.ExecuteReader());
  256. var endTime = DateTime.Now;
  257. optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
  258. CustomViewCollection retval = subDomain.GetCollection<CustomViewCollection>();
  259. foreach (var item in result)
  260. {
  261. CustomView newItem = retval.NewItem();
  262. LoadDataRow(item, newItem);
  263. retval.AddItem(newItem);
  264. }
  265. retval.wrappedClass.AcceptChanges();
  266. retval.wrappedClass.EndLoadData();
  267. dc.Connection.Close();
  268. return retval;
  269. }
  270. private static void LoadDataRow(CustomViewQuery item, CustomView newItem)
  271. {
  272. newItem.wrappedClass["big_field"] = StringHelper.ConvertToDatabase(item.BigField);
  273. newItem.wrappedClass["created_by"] = StringHelper.ConvertToDatabase(item.CreatedBy);
  274. newItem.wrappedClass["created_date"] = StringHelper.ConvertToDatabase(item.CreatedDate);
  275. newItem.wrappedClass["modified_by"] = StringHelper.ConvertToDatabase(item.ModifiedBy);
  276. newItem.wrappedClass["modified_date"] = StringHelper.ConvertToDatabase(item.ModifiedDate);
  277. newItem.wrappedClass["name"] = StringHelper.ConvertToDatabase(item.Name);
  278. newItem.wrappedClass["simple_id"] = item.SimpleId;
  279. newItem.wrappedClass["time_stamp"] = item.TimeStamp;
  280. }
  281. #region Search Members
  282. /// <summary>
  283. /// Creates a search object to query this collection.
  284. /// </summary>
  285. IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)
  286. {
  287. return (IBusinessObjectSearch)this.CreateSearchObject(searchType);
  288. }
  289. /// <summary>
  290. /// Creates a search object to query this collection.
  291. /// </summary>
  292. public CustomViewSearch CreateSearchObject(SearchType searchType)
  293. {
  294. return null;
  295. }
  296. #endregion
  297. /// <summary>
  298. /// Creates a sorted dataview of this collection ordered by the specified parameter
  299. /// </summary>
  300. public DataView GetSortedCustomViewList(string sortString)
  301. {
  302. try
  303. {
  304. return wrappedClass.GetSortedCustomViewList(sortString);
  305. }
  306. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  307. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  308. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  309. }
  310. /// <summary>
  311. /// Returns an enumerator that can be used to iterate through the collection.
  312. /// </summary>
  313. /// <returns>An Enumerator that can iterate through the objects in this collection.</returns>
  314. public System.Collections.IEnumerator GetEnumerator()
  315. {
  316. try
  317. {
  318. return new CustomViewEnumerator(wrappedClass.GetEnumerator());
  319. }
  320. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  321. catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new Widgetsphere.Core.Exceptions.UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
  322. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  323. }
  324. System.Collections.Generic.IEnumerator<CustomView> System.Collections.Generic.IEnumerable<CustomView>.GetEnumerator()
  325. {
  326. var retval = new List<CustomView>();
  327. foreach (CustomView item in this)
  328. {
  329. retval.Add(item);
  330. }
  331. return retval.GetEnumerator();
  332. }
  333. /// <summary>
  334. /// Rejects all the changes associate with business object in this collection.
  335. /// </summary>
  336. /// <returns>void</returns>
  337. public void RejectChanges()
  338. {
  339. var coll = (DomainCustomViewCollection)this.wrappedClass;
  340. coll.RejectChanges();
  341. }
  342. /// <summary>
  343. /// Takes an IVisitor object and iterates through each item in this collection
  344. /// </summary>
  345. /// <param name="visitor">The object that processes each collection item</param>
  346. public virtual void ProcessVisitor(IVisitor visitor)
  347. {
  348. if (visitor == null) throw new Exception("This object cannot be null.");
  349. foreach (IBusinessObject item in this)
  350. {
  351. visitor.Visit(item);
  352. }
  353. }
  354. #region Static SQL Methods
  355. internal static string GetFieldAliasFromFieldNameSqlMapping(string alias)
  356. {
  357. alias = alias.Replace("[", string.Empty).Replace("]", string.Empty);
  358. switch (alias.ToLower())
  359. {
  360. case "big_field": return "bigfield";
  361. case "created_by": return "createdby";
  362. case "created_date": return "createddate";
  363. case "modified_by": return "modifiedby";
  364. case "modified_date": return "modifieddate";
  365. case "name": return "name";
  366. case "simple_id": return "simpleid";
  367. case "time_stamp": return "timestamp";
  368. default: throw new Exception("The select clause is not valid.");
  369. }
  370. }
  371. internal static string GetTableFromFieldAliasSqlMapping(string alias)
  372. {
  373. switch (alias.ToLower())
  374. {
  375. case "bigfield": return "CUSTOM_VIEW";
  376. case "createdby": return "CUSTOM_VIEW";
  377. case "createddate": return "CUSTOM_VIEW";
  378. case "modifiedby": return "CUSTOM_VIEW";
  379. case "modifieddate": return "CUSTOM_VIEW";
  380. case "name": return "CUSTOM_VIEW";
  381. case "simpleid": return "CUSTOM_VIEW";
  382. case "timestamp": return "CUSTOM_VIEW";
  383. default: throw new Exception("The select clause is not valid.");
  384. }
  385. }
  386. internal static string GetTableFromFieldNameSqlMapping(string field)
  387. {
  388. switch (field.ToLower())
  389. {
  390. case "big_field": return "CUSTOM_VIEW";
  391. case "created_by": return "CUSTOM_VIEW";
  392. case "created_date": return "CUSTOM_VIEW";
  393. case "modified_by": return "CUSTOM_VIEW";
  394. case "modified_date": return "CUSTOM_VIEW";
  395. case "name": return "CUSTOM_VIEW";
  396. case "simple_id": return "CUSTOM_VIEW";
  397. case "time_stamp": return "CUSTOM_VIEW";
  398. default: throw new Exception("The select clause is not valid.");
  399. }
  400. }
  401. internal static string GetRemappedLinqSql(string sql, string parentAlias, LinqSQLFromClauseCollection childTables)
  402. {
  403. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[big_field\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[big_field]", RegexOptions.IgnoreCase);
  404. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[created_by\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[created_by]", RegexOptions.IgnoreCase);
  405. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[created_date\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[created_date]", RegexOptions.IgnoreCase);
  406. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modified_by\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[modified_by]", RegexOptions.IgnoreCase);
  407. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modified_date\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[modified_date]", RegexOptions.IgnoreCase);
  408. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[name\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[name]", RegexOptions.IgnoreCase);
  409. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[simple_id\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[simple_id]", RegexOptions.IgnoreCase);
  410. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[time_stamp\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[time_stamp]", RegexOptions.IgnoreCase);
  411. return sql;
  412. }
  413. #endregion
  414. internal static string GetPagedSQL(List<LinqSQLField> fieldList, LinqSQLFromClauseCollection fromLinkList, string whereClause, object paging, QueryOptimizer optimizer)
  415. {
  416. var sb = new StringBuilder();
  417. var paging2 = (CustomViewPaging)paging;
  418. //Calculate the SELECT clause
  419. sb.Append("SELECT ");
  420. int index = 0;
  421. foreach (LinqSQLField field in fieldList)
  422. {
  423. sb.Append("[t0].[" + field.Name + "]");
  424. if (index < fieldList.Count - 1) sb.Append(", ");
  425. index++;
  426. }
  427. sb.AppendLine();
  428. sb.AppendLine("FROM (");
  429. //Calculate the Inner SELECT clause
  430. sb.Append("SELECT ");
  431. index = 0;
  432. foreach (var field in fieldList)
  433. {
  434. sb.Append(field.GetSQL(false));
  435. if (index < fieldList.Count - 1) sb.Append(", ");
  436. index++;
  437. }
  438. sb.AppendLine();
  439. //If there is no sort then add primary key
  440. if (paging2.OrderByList.Count == 0)
  441. {
  442. }
  443. //Determine the paging sort
  444. var orderByClause = string.Empty;
  445. foreach (var fieldItem in paging2.OrderByList)
  446. {
  447. if (!string.IsNullOrEmpty(orderByClause)) orderByClause += ", ";
  448. switch (fieldItem.Field.ToString().ToLower())
  449. {
  450. case "bigfield": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[big_field]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  451. case "createdby": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[created_by]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  452. case "createddate": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[created_date]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  453. case "modifiedby": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[modified_by]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  454. case "modifieddate": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[modified_date]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  455. case "name": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[name]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  456. case "simpleid": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[simple_id]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  457. case "timestamp": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[time_stamp]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  458. default: throw new Exception("The order by clause is not valid.");
  459. }
  460. }
  461. sb.AppendLine(", ROW_NUMBER() OVER (ORDER BY " + orderByClause + ") AS Row");
  462. //Calculate the FROM clause
  463. index = 0;
  464. sb.Append("FROM ");
  465. foreach (LinqSQLFromClause fromClause in fromLinkList)
  466. {
  467. sb.Append("[" + fromClause.Schema + "].[" + fromClause.TableName + "] AS [" + fromClause.Alias + "] ");
  468. if (optimizer.NoLocking) sb.Append("WITH (NOLOCK)");
  469. if (!string.IsNullOrEmpty(fromClause.LinkClause)) sb.Append(fromClause.LinkClause + " ");
  470. if (index < fromLinkList.Count - 1)
  471. {
  472. sb.AppendLine();
  473. sb.Append("LEFT OUTER JOIN ");
  474. }
  475. index++;
  476. }
  477. sb.AppendLine();
  478. //Calculate the WHERE clause
  479. if (!string.IsNullOrEmpty(whereClause))
  480. {
  481. foreach (LinqSQLFromClause fromClause in fromLinkList)
  482. {
  483. //Only process table that were original and not inserted above
  484. if (fromClause.AnchorAlias == string.Empty)
  485. {
  486. if (fromClause.TableName == "ANCESTOR") whereClause = Acme.TestModel.Business.Objects.AncestorCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  487. else if (fromClause.TableName == "CHILD") whereClause = Acme.TestModel.Business.Objects.ChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  488. else if (fromClause.TableName == "DESCENDANT") whereClause = Acme.TestModel.Business.Objects.DescendantCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  489. else if (fromClause.TableName == "DESCENDANT_PARENT") whereClause = Acme.TestModel.Business.Objects.DescendantParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  490. else if (fromClause.TableName == "DOUBLE_KEY_IDENTITY") whereClause = Acme.TestModel.Business.Objects.DoubleKeyIdentityCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  491. else if (fromClause.TableName == "DOUBLE_LINK_ONE_ONE_CHILD") whereClause = Acme.TestModel.Business.Objects.DoubleLinkOneOneChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  492. else if (fromClause.TableName == "DOUBLE_LINK_ONE_ONE_PARENT") whereClause = Acme.TestModel.Business.Objects.DoubleLinkOneOneParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  493. else if (fromClause.TableName == "GUID_LINK_CHILD") whereClause = Acme.TestModel.Business.Objects.GuidLinkChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  494. else if (fromClause.TableName == "GUID_LINK_PARENT") whereClause = Acme.TestModel.Business.Objects.GuidLinkParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  495. else if (fromClause.TableName == "LEFT") whereClause = Acme.TestModel.Business.Objects.LeftCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  496. else if (fromClause.TableName == "LEFT_RIGHT") whereClause = Acme.TestModel.Business.Objects.LeftRightCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  497. else if (fromClause.TableName == "MANY_TYPES") whereClause = Acme.TestModel.Business.Objects.ManyTypesCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  498. else if (fromClause.TableName == "ONE_TO_ONE_CHILD") whereClause = Acme.TestModel.Business.Objects.OneToOneChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  499. else if (fromClause.TableName == "ONE_TO_ONE_PARENT") whereClause = Acme.TestModel.Business.Objects.OneToOneParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  500. else if (fromClause.TableName == "PARENT") whereClause = Acme.TestModel.Business.Objects.ParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  501. else if (fromClause.TableName == "PARENT_TYPE") whereClause = Acme.TestModel.Business.Objects.ParentTypeCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  502. else if (fromClause.TableName == "RIGHT") whereClause = Acme.TestModel.Business.Objects.RightCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  503. else if (fromClause.TableName == "SIMPLE") whereClause = Acme.TestModel.Business.Objects.SimpleCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  504. else if (fromClause.TableName == "TREE_NODE") whereClause = Acme.TestModel.Business.Objects.TreeNodeCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
  505. }
  506. }
  507. sb.Append("WHERE " + whereClause);
  508. }
  509. sb.AppendLine(") AS [t0]");
  510. sb.AppendLine("WHERE (Row >= " + (((paging2.PageIndex - 1) * paging2.RecordsperPage) + 1) + ") AND (Row <= " + (paging2.PageIndex * paging2.RecordsperPage) + ")");
  511. return sb.ToString();
  512. }
  513. #endregion
  514. /// <summary>
  515. /// Get the maximum value of the field for all objects
  516. /// </summary>
  517. /// <param name="select">The field to aggregate</param>
  518. public static int? GetMax(Expression<Func<CustomViewQuery, int>> select)
  519. {
  520. return GetMax(select, x => true);
  521. }
  522. /// <summary>
  523. /// Get the maximum value of the field in the set of records that match the Where condition
  524. /// </summary>
  525. /// <param name="select">The field to aggregate</param>
  526. /// <param name="where">The expression that determines the records selected</param>
  527. public static int? GetMax(Expression<Func<CustomViewQuery, int>> select, Expression<Func<CustomViewQuery, bool>> where)
  528. {
  529. return GetMax(select, where, new QueryOptimizer());
  530. }
  531. /// <summary>
  532. /// Get the maximum value of the field in the set of records that match the Where condition
  533. /// </summary>
  534. /// <param name="select">The field to aggregate</param>
  535. /// <param name="where">The expression that determines the records selected</param>
  536. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  537. public static int? GetMax(Expression<Func<CustomViewQuery, int>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  538. {
  539. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  540. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  541. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  542. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  543. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  544. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  545. switch (fieldName.ToLower())
  546. {
  547. case "bigfield": fieldName = "big_field"; break;
  548. case "createdby": fieldName = "created_by"; break;
  549. case "createddate": fieldName = "created_date"; break;
  550. case "modifiedby": fieldName = "modified_by"; break;
  551. case "modifieddate": fieldName = "modified_date"; break;
  552. case "name": fieldName = "name"; break;
  553. case "simpleid": fieldName = "simple_id"; break;
  554. case "timestamp": fieldName = "time_stamp"; break;
  555. default: throw new Exception("The select clause is not valid.");
  556. }
  557. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  558. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  559. dc.Connection.Open();
  560. object p = cmd.ExecuteScalar();
  561. dc.Connection.Close();
  562. if (p == System.DBNull.Value)
  563. return null;
  564. else
  565. return (int)p;
  566. }
  567. /// <summary>
  568. /// Get the maximum value of the field for all objects
  569. /// </summary>
  570. /// <param name="select">The field to aggregate</param>
  571. public static int? GetMax(Expression<Func<CustomViewQuery, int?>> select)
  572. {
  573. return GetMax(select, x => true);
  574. }
  575. /// <summary>
  576. /// Get the maximum value of the field in the set of records that match the Where condition
  577. /// </summary>
  578. /// <param name="select">The field to aggregate</param>
  579. /// <param name="where">The expression that determines the records selected</param>
  580. public static int? GetMax(Expression<Func<CustomViewQuery, int?>> select, Expression<Func<CustomViewQuery, bool>> where)
  581. {
  582. return GetMax(select, where, new QueryOptimizer());
  583. }
  584. /// <summary>
  585. /// Get the maximum value of the field in the set of records that match the Where condition
  586. /// </summary>
  587. /// <param name="select">The field to aggregate</param>
  588. /// <param name="where">The expression that determines the records selected</param>
  589. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  590. public static int? GetMax(Expression<Func<CustomViewQuery, int?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  591. {
  592. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  593. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  594. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  595. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  596. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  597. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  598. switch (fieldName.ToLower())
  599. {
  600. case "bigfield": fieldName = "big_field"; break;
  601. case "createdby": fieldName = "created_by"; break;
  602. case "createddate": fieldName = "created_date"; break;
  603. case "modifiedby": fieldName = "modified_by"; break;
  604. case "modifieddate": fieldName = "modified_date"; break;
  605. case "name": fieldName = "name"; break;
  606. case "simpleid": fieldName = "simple_id"; break;
  607. case "timestamp": fieldName = "time_stamp"; break;
  608. default: throw new Exception("The select clause is not valid.");
  609. }
  610. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  611. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  612. dc.Connection.Open();
  613. object p = cmd.ExecuteScalar();
  614. dc.Connection.Close();
  615. if (p == System.DBNull.Value)
  616. return null;
  617. else
  618. return (int?)p;
  619. }
  620. /// <summary>
  621. /// Get the maximum value of the field for all objects
  622. /// </summary>
  623. /// <param name="select">The field to aggregate</param>
  624. public static Single? GetMax(Expression<Func<CustomViewQuery, Single>> select)
  625. {
  626. return GetMax(select, x => true);
  627. }
  628. /// <summary>
  629. /// Get the maximum value of the field in the set of records that match the Where condition
  630. /// </summary>
  631. /// <param name="select">The field to aggregate</param>
  632. /// <param name="where">The expression that determines the records selected</param>
  633. public static Single? GetMax(Expression<Func<CustomViewQuery, Single>> select, Expression<Func<CustomViewQuery, bool>> where)
  634. {
  635. return GetMax(select, where, new QueryOptimizer());
  636. }
  637. /// <summary>
  638. /// Get the maximum value of the field in the set of records that match the Where condition
  639. /// </summary>
  640. /// <param name="select">The field to aggregate</param>
  641. /// <param name="where">The expression that determines the records selected</param>
  642. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  643. public static Single? GetMax(Expression<Func<CustomViewQuery, Single>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  644. {
  645. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  646. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  647. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  648. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  649. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  650. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  651. switch (fieldName.ToLower())
  652. {
  653. case "bigfield": fieldName = "big_field"; break;
  654. case "createdby": fieldName = "created_by"; break;
  655. case "createddate": fieldName = "created_date"; break;
  656. case "modifiedby": fieldName = "modified_by"; break;
  657. case "modifieddate": fieldName = "modified_date"; break;
  658. case "name": fieldName = "name"; break;
  659. case "simpleid": fieldName = "simple_id"; break;
  660. case "timestamp": fieldName = "time_stamp"; break;
  661. default: throw new Exception("The select clause is not valid.");
  662. }
  663. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  664. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  665. dc.Connection.Open();
  666. object p = cmd.ExecuteScalar();
  667. dc.Connection.Close();
  668. if (p == System.DBNull.Value)
  669. return null;
  670. else
  671. return (Single)p;
  672. }
  673. /// <summary>
  674. /// Get the maximum value of the field for all objects
  675. /// </summary>
  676. /// <param name="select">The field to aggregate</param>
  677. public static Single? GetMax(Expression<Func<CustomViewQuery, Single?>> select)
  678. {
  679. return GetMax(select, x => true);
  680. }
  681. /// <summary>
  682. /// Get the maximum value of the field in the set of records that match the Where condition
  683. /// </summary>
  684. /// <param name="select">The field to aggregate</param>
  685. /// <param name="where">The expression that determines the records selected</param>
  686. public static Single? GetMax(Expression<Func<CustomViewQuery, Single?>> select, Expression<Func<CustomViewQuery, bool>> where)
  687. {
  688. return GetMax(select, where, new QueryOptimizer());
  689. }
  690. /// <summary>
  691. /// Get the maximum value of the field in the set of records that match the Where condition
  692. /// </summary>
  693. /// <param name="select">The field to aggregate</param>
  694. /// <param name="where">The expression that determines the records selected</param>
  695. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  696. public static Single? GetMax(Expression<Func<CustomViewQuery, Single?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  697. {
  698. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  699. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  700. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  701. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  702. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  703. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  704. switch (fieldName.ToLower())
  705. {
  706. case "bigfield": fieldName = "big_field"; break;
  707. case "createdby": fieldName = "created_by"; break;
  708. case "createddate": fieldName = "created_date"; break;
  709. case "modifiedby": fieldName = "modified_by"; break;
  710. case "modifieddate": fieldName = "modified_date"; break;
  711. case "name": fieldName = "name"; break;
  712. case "simpleid": fieldName = "simple_id"; break;
  713. case "timestamp": fieldName = "time_stamp"; break;
  714. default: throw new Exception("The select clause is not valid.");
  715. }
  716. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  717. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  718. dc.Connection.Open();
  719. object p = cmd.ExecuteScalar();
  720. dc.Connection.Close();
  721. if (p == System.DBNull.Value)
  722. return null;
  723. else
  724. return (Single?)p;
  725. }
  726. /// <summary>
  727. /// Get the maximum value of the field for all objects
  728. /// </summary>
  729. /// <param name="select">The field to aggregate</param>
  730. public static double? GetMax(Expression<Func<CustomViewQuery, double>> select)
  731. {
  732. return GetMax(select, x => true);
  733. }
  734. /// <summary>
  735. /// Get the maximum value of the field in the set of records that match the Where condition
  736. /// </summary>
  737. /// <param name="select">The field to aggregate</param>
  738. /// <param name="where">The expression that determines the records selected</param>
  739. public static double? GetMax(Expression<Func<CustomViewQuery, double>> select, Expression<Func<CustomViewQuery, bool>> where)
  740. {
  741. return GetMax(select, where, new QueryOptimizer());
  742. }
  743. /// <summary>
  744. /// Get the maximum value of the field in the set of records that match the Where condition
  745. /// </summary>
  746. /// <param name="select">The field to aggregate</param>
  747. /// <param name="where">The expression that determines the records selected</param>
  748. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  749. public static double? GetMax(Expression<Func<CustomViewQuery, double>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  750. {
  751. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  752. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  753. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  754. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  755. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  756. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  757. switch (fieldName.ToLower())
  758. {
  759. case "bigfield": fieldName = "big_field"; break;
  760. case "createdby": fieldName = "created_by"; break;
  761. case "createddate": fieldName = "created_date"; break;
  762. case "modifiedby": fieldName = "modified_by"; break;
  763. case "modifieddate": fieldName = "modified_date"; break;
  764. case "name": fieldName = "name"; break;
  765. case "simpleid": fieldName = "simple_id"; break;
  766. case "timestamp": fieldName = "time_stamp"; break;
  767. default: throw new Exception("The select clause is not valid.");
  768. }
  769. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  770. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  771. dc.Connection.Open();
  772. object p = cmd.ExecuteScalar();
  773. dc.Connection.Close();
  774. if (p == System.DBNull.Value)
  775. return null;
  776. else
  777. return (double)p;
  778. }
  779. /// <summary>
  780. /// Get the maximum value of the field for all objects
  781. /// </summary>
  782. /// <param name="select">The field to aggregate</param>
  783. public static double? GetMax(Expression<Func<CustomViewQuery, double?>> select)
  784. {
  785. return GetMax(select, x => true);
  786. }
  787. /// <summary>
  788. /// Get the maximum value of the field in the set of records that match the Where condition
  789. /// </summary>
  790. /// <param name="select">The field to aggregate</param>
  791. /// <param name="where">The expression that determines the records selected</param>
  792. public static double? GetMax(Expression<Func<CustomViewQuery, double?>> select, Expression<Func<CustomViewQuery, bool>> where)
  793. {
  794. return GetMax(select, where, new QueryOptimizer());
  795. }
  796. /// <summary>
  797. /// Get the maximum value of the field in the set of records that match the Where condition
  798. /// </summary>
  799. /// <param name="select">The field to aggregate</param>
  800. /// <param name="where">The expression that determines the records selected</param>
  801. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  802. public static double? GetMax(Expression<Func<CustomViewQuery, double?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  803. {
  804. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  805. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  806. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  807. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  808. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  809. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  810. switch (fieldName.ToLower())
  811. {
  812. case "bigfield": fieldName = "big_field"; break;
  813. case "createdby": fieldName = "created_by"; break;
  814. case "createddate": fieldName = "created_date"; break;
  815. case "modifiedby": fieldName = "modified_by"; break;
  816. case "modifieddate": fieldName = "modified_date"; break;
  817. case "name": fieldName = "name"; break;
  818. case "simpleid": fieldName = "simple_id"; break;
  819. case "timestamp": fieldName = "time_stamp"; break;
  820. default: throw new Exception("The select clause is not valid.");
  821. }
  822. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  823. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  824. dc.Connection.Open();
  825. object p = cmd.ExecuteScalar();
  826. dc.Connection.Close();
  827. if (p == System.DBNull.Value)
  828. return null;
  829. else
  830. return (double?)p;
  831. }
  832. /// <summary>
  833. /// Get the maximum value of the field for all objects
  834. /// </summary>
  835. /// <param name="select">The field to aggregate</param>
  836. public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal>> select)
  837. {
  838. return GetMax(select, x => true);
  839. }
  840. /// <summary>
  841. /// Get the maximum value of the field in the set of records that match the Where condition
  842. /// </summary>
  843. /// <param name="select">The field to aggregate</param>
  844. /// <param name="where">The expression that determines the records selected</param>
  845. public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal>> select, Expression<Func<CustomViewQuery, bool>> where)
  846. {
  847. return GetMax(select, where, new QueryOptimizer());
  848. }
  849. /// <summary>
  850. /// Get the maximum value of the field in the set of records that match the Where condition
  851. /// </summary>
  852. /// <param name="select">The field to aggregate</param>
  853. /// <param name="where">The expression that determines the records selected</param>
  854. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  855. public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  856. {
  857. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  858. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  859. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  860. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  861. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  862. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  863. switch (fieldName.ToLower())
  864. {
  865. case "bigfield": fieldName = "big_field"; break;
  866. case "createdby": fieldName = "created_by"; break;
  867. case "createddate": fieldName = "created_date"; break;
  868. case "modifiedby": fieldName = "modified_by"; break;
  869. case "modifieddate": fieldName = "modified_date"; break;
  870. case "name": fieldName = "name"; break;
  871. case "simpleid": fieldName = "simple_id"; break;
  872. case "timestamp": fieldName = "time_stamp"; break;
  873. default: throw new Exception("The select clause is not valid.");
  874. }
  875. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  876. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  877. dc.Connection.Open();
  878. object p = cmd.ExecuteScalar();
  879. dc.Connection.Close();
  880. if (p == System.DBNull.Value)
  881. return null;
  882. else
  883. return (decimal)p;
  884. }
  885. /// <summary>
  886. /// Get the maximum value of the field for all objects
  887. /// </summary>
  888. /// <param name="select">The field to aggregate</param>
  889. public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal?>> select)
  890. {
  891. return GetMax(select, x => true);
  892. }
  893. /// <summary>
  894. /// Get the maximum value of the field in the set of records that match the Where condition
  895. /// </summary>
  896. /// <param name="select">The field to aggregate</param>
  897. /// <param name="where">The expression that determines the records selected</param>
  898. public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal?>> select, Expression<Func<CustomViewQuery, bool>> where)
  899. {
  900. return GetMax(select, where, new QueryOptimizer());
  901. }
  902. /// <summary>
  903. /// Get the maximum value of the field in the set of records that match the Where condition
  904. /// </summary>
  905. /// <param name="select">The field to aggregate</param>
  906. /// <param name="where">The expression that determines the records selected</param>
  907. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  908. public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
  909. {
  910. var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  911. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  912. Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
  913. var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
  914. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  915. string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
  916. switch (fieldName.ToLower())
  917. {
  918. case "bigfield": fieldName = "big_field"; break;
  919. case "createdby": fieldName = "created_by"; break;
  920. case "createddate": fieldName = "created_date"; break;
  921. case "modifiedby": fieldName = "modified_by"; break;
  922. case "modifieddate": fieldName = "modified_date"; break;
  923. case "name": fieldName = "name"; break;
  924. case "simpleid": fieldName = "simple_id"; break;
  925. case "timestamp": fieldName = "time_stamp"; break;
  926. default: throw new Exception("The select clause is not valid.");
  927. }
  928. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
  929. cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
  930. dc.Connection.Open();
  931. object p = cmd.ExecuteScalar();
  932. dc.Connection.Close();
  933. if (p == System.DBNull.Value)
  934. return null;
  935. else
  936. return (decimal?)p;
  937. }
  938. /// <summary>
  939. /// Get the maximum value of the field for all objec…

Large files files are truncated, but you can click here to view the full file