/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
- using System;
- using System.Linq;
- using System.Data;
- using System.Xml;
- using System.Collections.Generic;
- using System.Collections;
- using System.Runtime.Serialization;
- using System.ComponentModel;
- using Acme.TestModel.Business.Rules;
- using Acme.TestModel.Business.SelectCommands;
- using Acme.TestModel.Domain.Objects;
- using Acme.TestModel.Domain.Views;
- using Widgetsphere.Core.DataAccess;
- using Widgetsphere.Core.Util;
- using Widgetsphere.Core.Logging;
- using Widgetsphere.Core.Exceptions;
- using System.IO;
- using System.Linq.Expressions;
- using Acme.TestModel.Business.Objects;
- using System.Data.Linq;
- using Acme.TestModel.Business.LINQ;
- using System.Text.RegularExpressions;
- using System.Text;
-
- namespace Acme.TestModel.Business.Views
- {
-
- /// <summary>
- /// The class representing the 'CustomView' virtual database table
- /// </summary>
- [Serializable()]
- public partial class CustomViewCollection : Widgetsphere.Core.DataAccess.BusinessCollectionBase, Widgetsphere.Core.DataAccess.IReadOnlyBusinessCollection, System.Collections.Generic.IEnumerable<CustomView>, System.ComponentModel.IListSource, System.Collections.IList
- {
- #region Member Variables
-
- internal DomainCustomViewCollection wrappedClass;
-
- #endregion
-
- #region Constructor / Initialize
-
- internal CustomViewCollection(DomainCustomViewCollection classToWrap)
- {
- wrappedClass = classToWrap;
- }
-
- /// <summary>
- /// The default constructor
- /// </summary>
- public CustomViewCollection()
- {
- var sd = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- wrappedClass = (DomainCustomViewCollection)sd.GetDomainCollection(Collections.CustomViewCollection);
- }
-
- #endregion
-
- #region Property Implementations
-
- /// <summary>
- /// Returns the internal object that this object wraps
- /// </summary>
- [System.ComponentModel.Browsable(false)]
- public object WrappedClass
- {
- get { return wrappedClass; }
- set { wrappedClass = (DomainCustomViewCollection)value; }
- }
-
- /// <summary>
- /// A reference to the SubDomain that holds this collection
- /// </summary>
- public SubDomain SubDomain
- {
- get
- {
- try
- {
- return wrappedClass.SubDomain;
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
- }
-
- /// <summary>
- /// Returns the number of items in this collection
- /// </summary>
- public override int Count
- {
- get
- {
- try
- {
- DataTable dt = wrappedClass.GetChanges(DataRowState.Deleted);
- if (dt == null)
- return wrappedClass.Count;
- else
- return wrappedClass.Count - dt.Rows.Count;
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
- }
-
- /// <summary>
- /// Determines the type of object contained by this collection.
- /// </summary>
- public Type ContainedType
- {
- get { return typeof(Acme.TestModel.Business.Views.CustomView); }
- }
-
- /// <summary>
- /// Determines the type of collection for this object.
- /// </summary>
- public Collections Collection
- {
- get { return Collections.CustomViewCollection; }
- }
-
- #endregion
-
- #region Enumerator
-
- /// <summary>
- /// Gets or sets the element at the specified index.
- /// </summary>
- /// <param name="index">The zero-based index of the element to get or set. </param>
- /// <returns>The element at the specified index.</returns>
- public CustomView this[int index]
- {
- get
- {
- try
- {
- var internalEnumerator = this.GetEnumerator();
- internalEnumerator.Reset();
- int ii = -1;
- while(ii < index)
- {
- internalEnumerator.MoveNext();
- ii++;
- }
- var retval = (CustomView)internalEnumerator.Current;
- if (retval.wrappedClass == null)
- {
- if (!((0 <= index) && (index < this.Count)))
- throw new IndexOutOfRangeException();
- else
- throw new Exception("The item is null. This is not a valid state.");
- }
- else return (CustomView)internalEnumerator.Current;
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
- }
-
- #endregion
-
- #region Methods
-
- /// <summary>
- /// Create a new object to later add to this collection
- /// </summary>
- internal CustomView NewItem()
- {
- try
- {
- lock (wrappedClass.SubDomain)
- {
- return new CustomView(wrappedClass.NewItem());
- }
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
-
- /// <summary>
- /// Add a newly created entity to this collection.
- /// </summary>
- internal virtual void AddItem(CustomView item)
- {
- try
- {
- lock (wrappedClass.SubDomain)
- {
- wrappedClass.AddItem((DomainCustomView)item.WrappedClass);
- }
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
-
- /// <summary>
- /// Execute the cached select commands
- /// </summary>
- public static CustomViewCollection RunSelect()
- {
- try
- {
- var returnVal = new CustomViewCollection(DomainCustomViewCollection.RunSelect());
- return returnVal;
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
-
- /// <summary>
- /// Using the specified Where expression, execute a query against the database to return a result set
- /// </summary>
- /// <param name="where">The expression that determines the records selected</param>
- public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where)
- {
- return RunSelect(where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Using the specified Where expression, execute a query against the database to return a paged result set
- /// </summary>
- public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where, CustomViewPaging paging)
- {
- return RunSelect(where, paging, new QueryOptimizer());
- }
-
- /// <summary>
- /// Using the specified Where expression, execute a query against the database to return a paged result set
- /// </summary>
- public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where, CustomViewPaging paging, QueryOptimizer optimizer)
- {
- if (paging == null) throw new Exception("The paging object cannot be null.");
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
-
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- var parser = LinqSQLParser.Create(cmd.CommandText, paging, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = parser.GetSQL(optimizer);
- dc.Connection.Open();
- var startTime = DateTime.Now;
- var result = dc.Translate<CustomViewQuery>(cmd.ExecuteReader());
- var endTime = DateTime.Now;
- optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
- CustomViewCollection retval = subDomain.GetCollection<CustomViewCollection>();
- foreach (var item in result)
- {
- var newItem = retval.NewItem();
- LoadDataRow(item, newItem);
- retval.AddItem(newItem);
- }
- retval.wrappedClass.AcceptChanges();
- retval.wrappedClass.EndLoadData();
- dc.Connection.Close();
- paging.RecordCount = GetCount(where);
- return retval;
- }
-
- /// <summary>
- /// Using the specified Where expression, execute a query against the database to return a result set
- /// </summary>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">The optimization object</param>
- public static CustomViewCollection RunSelect(Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
-
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = parser.GetSQL(optimizer);
- dc.Connection.Open();
- var startTime = DateTime.Now;
- var result = dc.Translate<CustomViewQuery>(cmd.ExecuteReader());
- var endTime = DateTime.Now;
- optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
- CustomViewCollection retval = subDomain.GetCollection<CustomViewCollection>();
- foreach (var item in result)
- {
- CustomView newItem = retval.NewItem();
- LoadDataRow(item, newItem);
- retval.AddItem(newItem);
- }
- retval.wrappedClass.AcceptChanges();
- retval.wrappedClass.EndLoadData();
- dc.Connection.Close();
- return retval;
- }
-
- private static void LoadDataRow(CustomViewQuery item, CustomView newItem)
- {
- newItem.wrappedClass["big_field"] = StringHelper.ConvertToDatabase(item.BigField);
- newItem.wrappedClass["created_by"] = StringHelper.ConvertToDatabase(item.CreatedBy);
- newItem.wrappedClass["created_date"] = StringHelper.ConvertToDatabase(item.CreatedDate);
- newItem.wrappedClass["modified_by"] = StringHelper.ConvertToDatabase(item.ModifiedBy);
- newItem.wrappedClass["modified_date"] = StringHelper.ConvertToDatabase(item.ModifiedDate);
- newItem.wrappedClass["name"] = StringHelper.ConvertToDatabase(item.Name);
- newItem.wrappedClass["simple_id"] = item.SimpleId;
- newItem.wrappedClass["time_stamp"] = item.TimeStamp;
- }
-
- #region Search Members
-
- /// <summary>
- /// Creates a search object to query this collection.
- /// </summary>
- IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)
- {
- return (IBusinessObjectSearch)this.CreateSearchObject(searchType);
- }
-
- /// <summary>
- /// Creates a search object to query this collection.
- /// </summary>
- public CustomViewSearch CreateSearchObject(SearchType searchType)
- {
- return null;
- }
-
- #endregion
-
- /// <summary>
- /// Creates a sorted dataview of this collection ordered by the specified parameter
- /// </summary>
- public DataView GetSortedCustomViewList(string sortString)
- {
- try
- {
- return wrappedClass.GetSortedCustomViewList(sortString);
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
-
- /// <summary>
- /// Returns an enumerator that can be used to iterate through the collection.
- /// </summary>
- /// <returns>An Enumerator that can iterate through the objects in this collection.</returns>
- public System.Collections.IEnumerator GetEnumerator()
- {
- try
- {
- return new CustomViewEnumerator(wrappedClass.GetEnumerator());
- }
- catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
- 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; }
- catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
- }
-
- System.Collections.Generic.IEnumerator<CustomView> System.Collections.Generic.IEnumerable<CustomView>.GetEnumerator()
- {
- var retval = new List<CustomView>();
- foreach (CustomView item in this)
- {
- retval.Add(item);
- }
- return retval.GetEnumerator();
- }
-
- /// <summary>
- /// Rejects all the changes associate with business object in this collection.
- /// </summary>
- /// <returns>void</returns>
- public void RejectChanges()
- {
- var coll = (DomainCustomViewCollection)this.wrappedClass;
- coll.RejectChanges();
- }
-
- /// <summary>
- /// Takes an IVisitor object and iterates through each item in this collection
- /// </summary>
- /// <param name="visitor">The object that processes each collection item</param>
- public virtual void ProcessVisitor(IVisitor visitor)
- {
- if (visitor == null) throw new Exception("This object cannot be null.");
- foreach (IBusinessObject item in this)
- {
- visitor.Visit(item);
- }
- }
-
- #region Static SQL Methods
-
- internal static string GetFieldAliasFromFieldNameSqlMapping(string alias)
- {
- alias = alias.Replace("[", string.Empty).Replace("]", string.Empty);
- switch (alias.ToLower())
- {
- case "big_field": return "bigfield";
- case "created_by": return "createdby";
- case "created_date": return "createddate";
- case "modified_by": return "modifiedby";
- case "modified_date": return "modifieddate";
- case "name": return "name";
- case "simple_id": return "simpleid";
- case "time_stamp": return "timestamp";
- default: throw new Exception("The select clause is not valid.");
- }
- }
-
- internal static string GetTableFromFieldAliasSqlMapping(string alias)
- {
- switch (alias.ToLower())
- {
- case "bigfield": return "CUSTOM_VIEW";
- case "createdby": return "CUSTOM_VIEW";
- case "createddate": return "CUSTOM_VIEW";
- case "modifiedby": return "CUSTOM_VIEW";
- case "modifieddate": return "CUSTOM_VIEW";
- case "name": return "CUSTOM_VIEW";
- case "simpleid": return "CUSTOM_VIEW";
- case "timestamp": return "CUSTOM_VIEW";
- default: throw new Exception("The select clause is not valid.");
- }
- }
-
- internal static string GetTableFromFieldNameSqlMapping(string field)
- {
- switch (field.ToLower())
- {
- case "big_field": return "CUSTOM_VIEW";
- case "created_by": return "CUSTOM_VIEW";
- case "created_date": return "CUSTOM_VIEW";
- case "modified_by": return "CUSTOM_VIEW";
- case "modified_date": return "CUSTOM_VIEW";
- case "name": return "CUSTOM_VIEW";
- case "simple_id": return "CUSTOM_VIEW";
- case "time_stamp": return "CUSTOM_VIEW";
- default: throw new Exception("The select clause is not valid.");
- }
- }
-
- internal static string GetRemappedLinqSql(string sql, string parentAlias, LinqSQLFromClauseCollection childTables)
- {
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[big_field\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[big_field]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[created_by\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[created_by]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[created_date\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[created_date]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modified_by\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[modified_by]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modified_date\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[modified_date]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[name\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[name]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[simple_id\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[simple_id]", RegexOptions.IgnoreCase);
- sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[time_stamp\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "CUSTOM_VIEW") + "].[time_stamp]", RegexOptions.IgnoreCase);
- return sql;
- }
-
- #endregion
-
- internal static string GetPagedSQL(List<LinqSQLField> fieldList, LinqSQLFromClauseCollection fromLinkList, string whereClause, object paging, QueryOptimizer optimizer)
- {
- var sb = new StringBuilder();
- var paging2 = (CustomViewPaging)paging;
-
- //Calculate the SELECT clause
- sb.Append("SELECT ");
- int index = 0;
- foreach (LinqSQLField field in fieldList)
- {
- sb.Append("[t0].[" + field.Name + "]");
- if (index < fieldList.Count - 1) sb.Append(", ");
- index++;
- }
- sb.AppendLine();
- sb.AppendLine("FROM (");
-
- //Calculate the Inner SELECT clause
- sb.Append("SELECT ");
- index = 0;
- foreach (var field in fieldList)
- {
- sb.Append(field.GetSQL(false));
- if (index < fieldList.Count - 1) sb.Append(", ");
- index++;
- }
- sb.AppendLine();
-
- //If there is no sort then add primary key
- if (paging2.OrderByList.Count == 0)
- {
- }
-
- //Determine the paging sort
- var orderByClause = string.Empty;
- foreach (var fieldItem in paging2.OrderByList)
- {
- if (!string.IsNullOrEmpty(orderByClause)) orderByClause += ", ";
- switch (fieldItem.Field.ToString().ToLower())
- {
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- default: throw new Exception("The order by clause is not valid.");
- }
- }
-
- sb.AppendLine(", ROW_NUMBER() OVER (ORDER BY " + orderByClause + ") AS Row");
- //Calculate the FROM clause
- index = 0;
- sb.Append("FROM ");
- foreach (LinqSQLFromClause fromClause in fromLinkList)
- {
- sb.Append("[" + fromClause.Schema + "].[" + fromClause.TableName + "] AS [" + fromClause.Alias + "] ");
- if (optimizer.NoLocking) sb.Append("WITH (NOLOCK)");
- if (!string.IsNullOrEmpty(fromClause.LinkClause)) sb.Append(fromClause.LinkClause + " ");
-
- if (index < fromLinkList.Count - 1)
- {
- sb.AppendLine();
- sb.Append("LEFT OUTER JOIN ");
- }
-
- index++;
- }
- sb.AppendLine();
-
- //Calculate the WHERE clause
- if (!string.IsNullOrEmpty(whereClause))
- {
- foreach (LinqSQLFromClause fromClause in fromLinkList)
- {
- //Only process table that were original and not inserted above
- if (fromClause.AnchorAlias == string.Empty)
- {
- if (fromClause.TableName == "ANCESTOR") whereClause = Acme.TestModel.Business.Objects.AncestorCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "CHILD") whereClause = Acme.TestModel.Business.Objects.ChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "DESCENDANT") whereClause = Acme.TestModel.Business.Objects.DescendantCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "DESCENDANT_PARENT") whereClause = Acme.TestModel.Business.Objects.DescendantParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "DOUBLE_KEY_IDENTITY") whereClause = Acme.TestModel.Business.Objects.DoubleKeyIdentityCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "DOUBLE_LINK_ONE_ONE_CHILD") whereClause = Acme.TestModel.Business.Objects.DoubleLinkOneOneChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "DOUBLE_LINK_ONE_ONE_PARENT") whereClause = Acme.TestModel.Business.Objects.DoubleLinkOneOneParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "GUID_LINK_CHILD") whereClause = Acme.TestModel.Business.Objects.GuidLinkChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "GUID_LINK_PARENT") whereClause = Acme.TestModel.Business.Objects.GuidLinkParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "LEFT") whereClause = Acme.TestModel.Business.Objects.LeftCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "LEFT_RIGHT") whereClause = Acme.TestModel.Business.Objects.LeftRightCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "MANY_TYPES") whereClause = Acme.TestModel.Business.Objects.ManyTypesCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "ONE_TO_ONE_CHILD") whereClause = Acme.TestModel.Business.Objects.OneToOneChildCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "ONE_TO_ONE_PARENT") whereClause = Acme.TestModel.Business.Objects.OneToOneParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "PARENT") whereClause = Acme.TestModel.Business.Objects.ParentCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "PARENT_TYPE") whereClause = Acme.TestModel.Business.Objects.ParentTypeCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "RIGHT") whereClause = Acme.TestModel.Business.Objects.RightCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "SIMPLE") whereClause = Acme.TestModel.Business.Objects.SimpleCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- else if (fromClause.TableName == "TREE_NODE") whereClause = Acme.TestModel.Business.Objects.TreeNodeCollection.GetRemappedLinqSql(whereClause, fromClause.Alias, fromLinkList);
- }
- }
- sb.Append("WHERE " + whereClause);
- }
-
- sb.AppendLine(") AS [t0]");
- sb.AppendLine("WHERE (Row >= " + (((paging2.PageIndex - 1) * paging2.RecordsperPage) + 1) + ") AND (Row <= " + (paging2.PageIndex * paging2.RecordsperPage) + ")");
-
- return sb.ToString();
- }
-
- #endregion
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static int? GetMax(Expression<Func<CustomViewQuery, int>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static int? GetMax(Expression<Func<CustomViewQuery, int>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static int? GetMax(Expression<Func<CustomViewQuery, int>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (int)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static int? GetMax(Expression<Func<CustomViewQuery, int?>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static int? GetMax(Expression<Func<CustomViewQuery, int?>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static int? GetMax(Expression<Func<CustomViewQuery, int?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (int?)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static Single? GetMax(Expression<Func<CustomViewQuery, Single>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static Single? GetMax(Expression<Func<CustomViewQuery, Single>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static Single? GetMax(Expression<Func<CustomViewQuery, Single>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (Single)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static Single? GetMax(Expression<Func<CustomViewQuery, Single?>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static Single? GetMax(Expression<Func<CustomViewQuery, Single?>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static Single? GetMax(Expression<Func<CustomViewQuery, Single?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (Single?)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static double? GetMax(Expression<Func<CustomViewQuery, double>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static double? GetMax(Expression<Func<CustomViewQuery, double>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static double? GetMax(Expression<Func<CustomViewQuery, double>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (double)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static double? GetMax(Expression<Func<CustomViewQuery, double?>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static double? GetMax(Expression<Func<CustomViewQuery, double?>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static double? GetMax(Expression<Func<CustomViewQuery, double?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (double?)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (decimal)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal?>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal?>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static decimal? GetMax(Expression<Func<CustomViewQuery, decimal?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (decimal?)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static string GetMax(Expression<Func<CustomViewQuery, string>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static string GetMax(Expression<Func<CustomViewQuery, string>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static string GetMax(Expression<Func<CustomViewQuery, string>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (string)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static DateTime? GetMax(Expression<Func<CustomViewQuery, DateTime>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static DateTime? GetMax(Expression<Func<CustomViewQuery, DateTime>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static DateTime? GetMax(Expression<Func<CustomViewQuery, DateTime>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (DateTime)p;
- }
-
- /// <summary>
- /// Get the maximum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static DateTime? GetMax(Expression<Func<CustomViewQuery, DateTime?>> select)
- {
- return GetMax(select, x => true);
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static DateTime? GetMax(Expression<Func<CustomViewQuery, DateTime?>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMax(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the maximum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static DateTime? GetMax(Expression<Func<CustomViewQuery, DateTime?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MAX([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (DateTime?)p;
- }
-
- /// <summary>
- /// Get the minimum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static int? GetMin(Expression<Func<CustomViewQuery, int>> select)
- {
- return GetMin(select, x => true);
- }
-
- /// <summary>
- /// Get the minimum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static int? GetMin(Expression<Func<CustomViewQuery, int>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMin(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the minimum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static int? GetMin(Expression<Func<CustomViewQuery, int>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MIN([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (int)p;
- }
-
- /// <summary>
- /// Get the minimum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static int? GetMin(Expression<Func<CustomViewQuery, int?>> select)
- {
- return GetMin(select, x => true);
- }
-
- /// <summary>
- /// Get the minimum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static int? GetMin(Expression<Func<CustomViewQuery, int?>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMin(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the minimum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static int? GetMin(Expression<Func<CustomViewQuery, int?>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
- Table<CustomViewQuery> template = dc.GetTable<CustomViewQuery>();
- var cmd = BusinessCollectionPersistableBase.GetCommand<CustomViewQuery>(dc, template, where);
- cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
- string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;
- switch (fieldName.ToLower())
- {
- case "bigfield": fieldName = "big_field"; break;
- case "createdby": fieldName = "created_by"; break;
- case "createddate": fieldName = "created_date"; break;
- case "modifiedby": fieldName = "modified_by"; break;
- case "modifieddate": fieldName = "modified_date"; break;
- case "name": fieldName = "name"; break;
- case "simpleid": fieldName = "simple_id"; break;
- case "timestamp": fieldName = "time_stamp"; break;
- default: throw new Exception("The select clause is not valid.");
- }
-
- var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);
- cmd.CommandText = "SELECT MIN([" + parser.GetTableAlias(fieldName, "CUSTOM_VIEW") + "]." + fieldName + ") " + parser.GetFromClause(optimizer) + " " + parser.GetWhereClause() + string.Empty;
- dc.Connection.Open();
- object p = cmd.ExecuteScalar();
- dc.Connection.Close();
- if (p == System.DBNull.Value)
- return null;
- else
- return (int?)p;
- }
-
- /// <summary>
- /// Get the minimum value of the field for all objects
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- public static Single? GetMin(Expression<Func<CustomViewQuery, Single>> select)
- {
- return GetMin(select, x => true);
- }
-
- /// <summary>
- /// Get the minimum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- public static Single? GetMin(Expression<Func<CustomViewQuery, Single>> select, Expression<Func<CustomViewQuery, bool>> where)
- {
- return GetMin(select, where, new QueryOptimizer());
- }
-
- /// <summary>
- /// Get the minimum value of the field in the set of records that match the Where condition
- /// </summary>
- /// <param name="select">The field to aggregate</param>
- /// <param name="where">The expression that determines the records selected</param>
- /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
- public static Single? GetMin(Expression<Func<CustomViewQuery, Single>> select, Expression<Func<CustomViewQuery, bool>> where, QueryOptimizer optimizer)
- {
- var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
- var dc = new DataContext(ConfigurationValues.Ge