PageRenderTime 64ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/EFTester/Acme.TestModel/Business/Objects/ManyTypesCollection.Generated.cs

#
C# | 1220 lines | 838 code | 107 blank | 275 comment | 120 complexity | ed094ca74b38412b208a45b485148d51 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.Data;
  3. using System.Xml;
  4. using System.Collections;
  5. using System.Runtime.Serialization;
  6. using System.ComponentModel;
  7. using Acme.TestModel.Business.Rules;
  8. using Acme.TestModel.Business.SelectCommands;
  9. using Acme.TestModel.Domain.Objects;
  10. using Widgetsphere.Core.DataAccess;
  11. using Widgetsphere.Core.Util;
  12. using Widgetsphere.Core.Logging;
  13. using Widgetsphere.Core.Exceptions;
  14. using Acme.TestModel.Business.LINQ;
  15. using System.IO;
  16. using System.Collections.Generic;
  17. using System.Linq.Expressions;
  18. using System.Data.Linq;
  19. using System.Linq;
  20. using System.Text;
  21. using Widgetsphere.Core.EventArgs;
  22. using System.Text.RegularExpressions;
  23. namespace Acme.TestModel.Business.Objects
  24. {
  25. /// <summary>
  26. /// The collection to hold 'ManyTypes' entities
  27. /// </summary>
  28. [Serializable()]
  29. public partial class ManyTypesCollection : Widgetsphere.Core.DataAccess.BusinessCollectionPersistableBase, Widgetsphere.Core.DataAccess.IPersistableBusinessCollection, System.IDisposable, System.ComponentModel.IListSource, System.Collections.IList, System.Collections.IEnumerator, System.Collections.Generic.IEnumerable<Acme.TestModel.Business.Objects.ManyTypes>, Widgetsphere.Core.DataAccess.IWrappingClass
  30. {
  31. #region Member Variables
  32. internal DomainManyTypesCollection wrappedClass;
  33. /// <summary>
  34. /// The parent subdomain object
  35. /// </summary>
  36. protected SubDomain _subDomain = null;
  37. #endregion
  38. #region Constructor / Initialize
  39. internal ManyTypesCollection(DomainManyTypesCollection classToWrap)
  40. {
  41. _subDomain = classToWrap.SubDomain;
  42. wrappedClass = classToWrap;
  43. }
  44. /// <summary>
  45. /// Constructor that enables you to specify a modifier
  46. /// </summary>
  47. /// <param name="modifier">Used in audit operations to track changes</param>
  48. public ManyTypesCollection(string modifier)
  49. {
  50. _subDomain = new SubDomain(modifier);
  51. ResetWrappedClass((DomainManyTypesCollection)_subDomain.GetDomainCollection(Collections.ManyTypesCollection));
  52. }
  53. /// <summary>
  54. /// The default constructor
  55. /// </summary>
  56. public ManyTypesCollection()
  57. {
  58. _subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);
  59. ResetWrappedClass((DomainManyTypesCollection)_subDomain.GetDomainCollection(Collections.ManyTypesCollection));
  60. }
  61. #endregion
  62. #region Property Implementations
  63. /// <summary>
  64. /// Returns the internal object that this object wraps
  65. /// </summary>
  66. [System.ComponentModel.Browsable(false)]
  67. internal virtual object WrappedClass
  68. {
  69. get { return wrappedClass ; }
  70. set { wrappedClass = (DomainManyTypesCollection)value ; }
  71. }
  72. //WrappingClass Interface
  73. object Widgetsphere.Core.DataAccess.IWrappingClass.WrappedClass
  74. {
  75. get { return this.WrappedClass; }
  76. set { this.WrappedClass = value; }
  77. }
  78. /// <summary>
  79. /// Specifies a modifier string to be used in the audit functionality
  80. /// </summary>
  81. public string Modifier
  82. {
  83. get
  84. {
  85. try
  86. {
  87. return wrappedClass.Modifier;
  88. }
  89. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  90. 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; }
  91. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  92. }
  93. internal set { wrappedClass.Modifier = value; }
  94. }
  95. /// <summary>
  96. /// A reference to the SubDomain that holds this collection
  97. /// </summary>
  98. public SubDomain SubDomain
  99. {
  100. get
  101. {
  102. try
  103. {
  104. return wrappedClass.SubDomain;
  105. }
  106. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  107. 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; }
  108. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  109. }
  110. }
  111. /// <summary>
  112. /// Returns the number of items in this collection
  113. /// </summary>
  114. public override int Count
  115. {
  116. get
  117. {
  118. try
  119. {
  120. lock (wrappedClass.SubDomain)
  121. {
  122. DataTable dt = wrappedClass.GetChanges(DataRowState.Deleted);
  123. if (dt == null) return wrappedClass.Count;
  124. else return wrappedClass.Count - dt.Rows.Count;
  125. }
  126. }
  127. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  128. 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; }
  129. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  130. }
  131. }
  132. /// <summary>
  133. /// Determines the type of object contained by this collection.
  134. /// </summary>
  135. public virtual Type ContainedType
  136. {
  137. get { return typeof(ManyTypes); }
  138. }
  139. /// <summary>
  140. /// Determines the type of collection for this object.
  141. /// </summary>
  142. public virtual Collections Collection
  143. {
  144. get { return Collections.ManyTypesCollection; }
  145. }
  146. #endregion
  147. #region Enumerator
  148. /// <summary>
  149. /// Gets or sets the element at the specified index.
  150. /// </summary>
  151. /// <param name="index">The zero-based index of the element to get or set. </param>
  152. /// <returns>The element at the specified index.</returns>
  153. public virtual ManyTypes this[int index]
  154. {
  155. get
  156. {
  157. try
  158. {
  159. var internalEnumerator = this.GetEnumerator();
  160. internalEnumerator.Reset();
  161. int ii = -1;
  162. while(ii < index)
  163. {
  164. internalEnumerator.MoveNext();
  165. ii++;
  166. }
  167. var retval = (ManyTypes)internalEnumerator.Current;
  168. if (retval.wrappedClass == null)
  169. {
  170. if (!((0 <= index) && (index < this.Count)))
  171. throw new IndexOutOfRangeException();
  172. else
  173. throw new Exception("The item is null. This is not a valid state.");
  174. }
  175. else return (ManyTypes)internalEnumerator.Current;
  176. }
  177. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  178. 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; }
  179. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  180. }
  181. }
  182. #endregion
  183. #region Methods
  184. /// <summary>
  185. /// Create a new object to later add to this collection
  186. /// </summary>
  187. public virtual ManyTypes NewItem(Guid key)
  188. {
  189. try
  190. {
  191. lock (wrappedClass.SubDomain)
  192. {
  193. return new ManyTypes(wrappedClass.NewItem(key));
  194. }
  195. }
  196. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  197. 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; }
  198. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  199. }
  200. /// <summary>
  201. /// Create a new object to later add to this collection
  202. /// </summary>
  203. public virtual ManyTypes NewItem()
  204. {
  205. try
  206. {
  207. lock (wrappedClass.SubDomain)
  208. {
  209. return new ManyTypes(wrappedClass.NewItem());
  210. }
  211. }
  212. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  213. 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; }
  214. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  215. }
  216. /// <summary>
  217. /// Add a newly created entity to this collection.
  218. /// </summary>
  219. public virtual void AddItem(ManyTypes item)
  220. {
  221. try
  222. {
  223. lock (wrappedClass.SubDomain)
  224. {
  225. wrappedClass.AddItem((DomainManyTypes)item.WrappedClass);
  226. }
  227. }
  228. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  229. 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; }
  230. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  231. }
  232. /// <summary>
  233. /// Determines if the specified item exists in this list
  234. /// </summary>
  235. /// <param name="item"></param>
  236. /// <returns></returns>
  237. public virtual bool Contains(Acme.TestModel.Business.Objects.ManyTypes item)
  238. {
  239. foreach (var o in this)
  240. {
  241. if (o == item) return true;
  242. }
  243. return false;
  244. }
  245. /// <summary>
  246. /// Determines the position in the list of the specified item, if it exists
  247. /// </summary>
  248. /// <param name="item"></param>
  249. /// <returns></returns>
  250. public virtual int IndexOf(Acme.TestModel.Business.Objects.ManyTypes item)
  251. {
  252. int index = 0;
  253. foreach (var o in this)
  254. {
  255. if (o == item) return index;
  256. index++;
  257. }
  258. return -1;
  259. }
  260. #region IListSource Members
  261. bool System.ComponentModel.IListSource.ContainsListCollection
  262. {
  263. get { return true; }
  264. }
  265. System.Collections.IList System.ComponentModel.IListSource.GetList()
  266. {
  267. var list = new System.Collections.Generic.List<Acme.TestModel.Business.Objects.ManyTypes>();
  268. list.AddRange(this);
  269. return list;
  270. }
  271. #endregion
  272. #region IList Members
  273. int System.Collections.IList.Add(object value)
  274. {
  275. if (!(value is Acme.TestModel.Business.Objects.ManyTypes))
  276. throw new System.Exception("The specified type is not valid!");
  277. var item = value as Acme.TestModel.Business.Objects.ManyTypes;
  278. this.AddItem(item);
  279. return this.Count;
  280. }
  281. void System.Collections.IList.Clear()
  282. {
  283. throw new System.NotImplementedException();
  284. }
  285. bool System.Collections.IList.Contains(object value)
  286. {
  287. if (!(value is Acme.TestModel.Business.Objects.ManyTypes))
  288. throw new System.Exception("The specified type is not valid!");
  289. var item = value as Acme.TestModel.Business.Objects.ManyTypes;
  290. return this.Contains(item);
  291. }
  292. int System.Collections.IList.IndexOf(object value)
  293. {
  294. if (!(value is Acme.TestModel.Business.Objects.ManyTypes))
  295. throw new System.Exception("The specified type is not valid!");
  296. var item = value as Acme.TestModel.Business.Objects.ManyTypes;
  297. return this.IndexOf(item);
  298. }
  299. void System.Collections.IList.Insert(int index, object value)
  300. {
  301. throw new System.NotImplementedException();
  302. }
  303. bool System.Collections.IList.IsFixedSize
  304. {
  305. get { return false; }
  306. }
  307. bool System.Collections.IList.IsReadOnly
  308. {
  309. get { return false; }
  310. }
  311. void System.Collections.IList.Remove(object value)
  312. {
  313. if (!(value is Acme.TestModel.Business.Objects.ManyTypes))
  314. throw new System.Exception("The specified type is not valid!");
  315. var item = value as Acme.TestModel.Business.Objects.ManyTypes;
  316. if (this.Contains(item))
  317. item.Delete();
  318. }
  319. void System.Collections.IList.RemoveAt(int index)
  320. {
  321. if ((0 <= index) && (index < this.Count))
  322. this[index].Delete();
  323. }
  324. object System.Collections.IList.this[int index]
  325. {
  326. get { return this[index]; }
  327. set { throw new System.NotImplementedException(); }
  328. }
  329. #endregion
  330. /// <summary>
  331. /// Takes an IVisitor object and iterates through each item in this collection
  332. /// </summary>
  333. /// <param name="visitor">The object that processes each collection item</param>
  334. public virtual void ProcessVisitor(IVisitor visitor)
  335. {
  336. if (visitor == null) throw new Exception("This object cannot be null.");
  337. lock(this)
  338. {
  339. foreach (IBusinessObject item in this)
  340. {
  341. visitor.Visit(item);
  342. }
  343. }
  344. }
  345. #region Static SQL Methods
  346. internal static string GetFieldAliasFromFieldNameSqlMapping(string alias)
  347. {
  348. alias = alias.Replace("[", string.Empty).Replace("]", string.Empty);
  349. switch (alias.ToLower())
  350. {
  351. case "guid_id": return "guidid";
  352. case "test_bigint": return "testbigint";
  353. case "test_binary": return "testbinary";
  354. case "test_bit": return "testbit";
  355. case "test_char": return "testchar";
  356. case "test_date": return "testdate";
  357. case "test_datetime": return "testdatetime";
  358. case "test_datetime2": return "testdatetime2";
  359. case "test_datetimeoffset": return "testdatetimeoffset";
  360. case "test_decimal": return "testdecimal";
  361. case "test_float": return "testfloat";
  362. case "test_image": return "testimage";
  363. case "test_int": return "testint";
  364. case "test_money": return "testmoney";
  365. case "test_nchar": return "testnchar";
  366. case "test_ntext": return "testntext";
  367. case "test_nvarchar": return "testnvarchar";
  368. case "test_real": return "testreal";
  369. case "test_smalldatetime": return "testsmalldatetime";
  370. case "test_smallint": return "testsmallint";
  371. case "test_smallmoney": return "testsmallmoney";
  372. case "test_text": return "testtext";
  373. case "test_time": return "testtime";
  374. case "test_tinyint": return "testtinyint";
  375. case "test_uniqueidentifier": return "testuniqueidentifier";
  376. case "test_varbinary": return "testvarbinary";
  377. case "test_varchar": return "testvarchar";
  378. case "test_xml": return "testxml";
  379. case "testcalculated": return "testcalculated";
  380. case "varcharmax": return "varcharmax";
  381. case "created_date": return "createddate";
  382. case "created_by": return "createdby";
  383. case "modified_date": return "modifieddate";
  384. case "modified_by": return "modifiedby";
  385. case "time_stamp": return "timestamp";
  386. default: throw new Exception("The select clause is not valid.");
  387. }
  388. }
  389. internal static string GetTableFromFieldAliasSqlMapping(string alias)
  390. {
  391. switch (alias.ToLower())
  392. {
  393. case "guidid": return "MANY_TYPES";
  394. case "testbigint": return "MANY_TYPES";
  395. case "testbinary": return "MANY_TYPES";
  396. case "testbit": return "MANY_TYPES";
  397. case "testchar": return "MANY_TYPES";
  398. case "testdate": return "MANY_TYPES";
  399. case "testdatetime": return "MANY_TYPES";
  400. case "testdatetime2": return "MANY_TYPES";
  401. case "testdatetimeoffset": return "MANY_TYPES";
  402. case "testdecimal": return "MANY_TYPES";
  403. case "testfloat": return "MANY_TYPES";
  404. case "testimage": return "MANY_TYPES";
  405. case "testint": return "MANY_TYPES";
  406. case "testmoney": return "MANY_TYPES";
  407. case "testnchar": return "MANY_TYPES";
  408. case "testntext": return "MANY_TYPES";
  409. case "testnvarchar": return "MANY_TYPES";
  410. case "testreal": return "MANY_TYPES";
  411. case "testsmalldatetime": return "MANY_TYPES";
  412. case "testsmallint": return "MANY_TYPES";
  413. case "testsmallmoney": return "MANY_TYPES";
  414. case "testtext": return "MANY_TYPES";
  415. case "testtime": return "MANY_TYPES";
  416. case "testtinyint": return "MANY_TYPES";
  417. case "testuniqueidentifier": return "MANY_TYPES";
  418. case "testvarbinary": return "MANY_TYPES";
  419. case "testvarchar": return "MANY_TYPES";
  420. case "testxml": return "MANY_TYPES";
  421. case "testcalculated": return "MANY_TYPES";
  422. case "varcharmax": return "MANY_TYPES";
  423. case "createdby": return "MANY_TYPES";
  424. case "createddate": return "MANY_TYPES";
  425. case "modifiedby": return "MANY_TYPES";
  426. case "modifieddate": return "MANY_TYPES";
  427. case "timestamp": return "MANY_TYPES";
  428. default: throw new Exception("The select clause is not valid.");
  429. }
  430. }
  431. internal static string GetTableFromFieldNameSqlMapping(string field)
  432. {
  433. switch (field.ToLower())
  434. {
  435. case "guid_id": return "MANY_TYPES";
  436. case "test_bigint": return "MANY_TYPES";
  437. case "test_binary": return "MANY_TYPES";
  438. case "test_bit": return "MANY_TYPES";
  439. case "test_char": return "MANY_TYPES";
  440. case "test_date": return "MANY_TYPES";
  441. case "test_datetime": return "MANY_TYPES";
  442. case "test_datetime2": return "MANY_TYPES";
  443. case "test_datetimeoffset": return "MANY_TYPES";
  444. case "test_decimal": return "MANY_TYPES";
  445. case "test_float": return "MANY_TYPES";
  446. case "test_image": return "MANY_TYPES";
  447. case "test_int": return "MANY_TYPES";
  448. case "test_money": return "MANY_TYPES";
  449. case "test_nchar": return "MANY_TYPES";
  450. case "test_ntext": return "MANY_TYPES";
  451. case "test_nvarchar": return "MANY_TYPES";
  452. case "test_real": return "MANY_TYPES";
  453. case "test_smalldatetime": return "MANY_TYPES";
  454. case "test_smallint": return "MANY_TYPES";
  455. case "test_smallmoney": return "MANY_TYPES";
  456. case "test_text": return "MANY_TYPES";
  457. case "test_time": return "MANY_TYPES";
  458. case "test_tinyint": return "MANY_TYPES";
  459. case "test_uniqueidentifier": return "MANY_TYPES";
  460. case "test_varbinary": return "MANY_TYPES";
  461. case "test_varchar": return "MANY_TYPES";
  462. case "test_xml": return "MANY_TYPES";
  463. case "testcalculated": return "MANY_TYPES";
  464. case "varcharmax": return "MANY_TYPES";
  465. case "created_by": return "MANY_TYPES";
  466. case "created_date": return "MANY_TYPES";
  467. case "modified_by": return "MANY_TYPES";
  468. case "modified_date": return "MANY_TYPES";
  469. case "time_stamp": return "MANY_TYPES";
  470. default: throw new Exception("The select clause is not valid.");
  471. }
  472. }
  473. internal static string GetRemappedLinqSql(string sql, string parentAlias, LinqSQLFromClauseCollection childTables)
  474. {
  475. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[guid_id\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[guid_id]", RegexOptions.IgnoreCase);
  476. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_bigint\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_bigint]", RegexOptions.IgnoreCase);
  477. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_binary\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_binary]", RegexOptions.IgnoreCase);
  478. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_bit\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_bit]", RegexOptions.IgnoreCase);
  479. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_char\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_char]", RegexOptions.IgnoreCase);
  480. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_date\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_date]", RegexOptions.IgnoreCase);
  481. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_datetime\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_datetime]", RegexOptions.IgnoreCase);
  482. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_datetime2\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_datetime2]", RegexOptions.IgnoreCase);
  483. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_datetimeoffset\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_datetimeoffset]", RegexOptions.IgnoreCase);
  484. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_decimal\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_decimal]", RegexOptions.IgnoreCase);
  485. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_float\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_float]", RegexOptions.IgnoreCase);
  486. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_image\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_image]", RegexOptions.IgnoreCase);
  487. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_int\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_int]", RegexOptions.IgnoreCase);
  488. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_money\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_money]", RegexOptions.IgnoreCase);
  489. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_nchar\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_nchar]", RegexOptions.IgnoreCase);
  490. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_ntext\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_ntext]", RegexOptions.IgnoreCase);
  491. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_nvarchar\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_nvarchar]", RegexOptions.IgnoreCase);
  492. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_real\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_real]", RegexOptions.IgnoreCase);
  493. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_smalldatetime\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_smalldatetime]", RegexOptions.IgnoreCase);
  494. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_smallint\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_smallint]", RegexOptions.IgnoreCase);
  495. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_smallmoney\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_smallmoney]", RegexOptions.IgnoreCase);
  496. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_text\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_text]", RegexOptions.IgnoreCase);
  497. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_time\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_time]", RegexOptions.IgnoreCase);
  498. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_tinyint\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_tinyint]", RegexOptions.IgnoreCase);
  499. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_uniqueidentifier\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_uniqueidentifier]", RegexOptions.IgnoreCase);
  500. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_varbinary\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_varbinary]", RegexOptions.IgnoreCase);
  501. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_varchar\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_varchar]", RegexOptions.IgnoreCase);
  502. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[test_xml\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[test_xml]", RegexOptions.IgnoreCase);
  503. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[testcalculated\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[testcalculated]", RegexOptions.IgnoreCase);
  504. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[varcharmax\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[varcharmax]", RegexOptions.IgnoreCase);
  505. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createdby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[createdby]", RegexOptions.IgnoreCase);
  506. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[createddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[createddate]", RegexOptions.IgnoreCase);
  507. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifiedby\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[modifiedby]", RegexOptions.IgnoreCase);
  508. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[modifieddate\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[modifieddate]", RegexOptions.IgnoreCase);
  509. sql = System.Text.RegularExpressions.Regex.Replace(sql, "\\[" + parentAlias + "\\]\\.\\[timestamp\\]", "[" + childTables.GetBaseAliasTable(parentAlias, "MANY_TYPES") + "].[timestamp]", RegexOptions.IgnoreCase);
  510. return sql;
  511. }
  512. internal static string GetPagedSQL(List<LinqSQLField> fieldList, LinqSQLFromClauseCollection fromLinkList, string whereClause, object paging, Widgetsphere.Core.DataAccess.QueryOptimizer optimizer)
  513. {
  514. var sb = new StringBuilder();
  515. var paging2 = (ManyTypesPaging)paging;
  516. //Calculate the SELECT clause
  517. sb.Append("SELECT ");
  518. int index = 0;
  519. foreach (LinqSQLField field in fieldList)
  520. {
  521. sb.Append("[t0].[" + field.Name + "]");
  522. if (index < fieldList.Count - 1) sb.Append(", ");
  523. index++;
  524. }
  525. sb.AppendLine();
  526. sb.AppendLine("FROM (");
  527. //Calculate the Inner SELECT clause
  528. sb.Append("SELECT ");
  529. index = 0;
  530. foreach (var field in fieldList)
  531. {
  532. sb.Append(field.GetSQL(false));
  533. if (index < fieldList.Count - 1) sb.Append(", ");
  534. index++;
  535. }
  536. sb.AppendLine();
  537. //If there is no sort then add primary key
  538. if (paging2.OrderByList.Count == 0)
  539. {
  540. paging2.OrderByList.Add(new ManyTypesPagingFieldItem(ManyTypes.FieldNameConstants.GuidId));
  541. }
  542. //Determine the paging sort
  543. var isPrimary = false;
  544. var orderByClause = string.Empty;
  545. foreach (var fieldItem in paging2.OrderByList)
  546. {
  547. if (!string.IsNullOrEmpty(orderByClause)) orderByClause += ", ";
  548. switch (fieldItem.Field.ToString().ToLower())
  549. {
  550. case "guidid": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[guid_id]" + (fieldItem.Ascending ? string.Empty : " DESC"); isPrimary = true;break;
  551. case "testbigint": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_bigint]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  552. case "testbinary": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_binary]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  553. case "testbit": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_bit]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  554. case "testchar": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_char]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  555. case "testdate": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_date]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  556. case "testdatetime": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_datetime]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  557. case "testdatetime2": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_datetime2]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  558. case "testdatetimeoffset": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_datetimeoffset]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  559. case "testdecimal": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_decimal]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  560. case "testfloat": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_float]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  561. case "testimage": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_image]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  562. case "testint": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_int]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  563. case "testmoney": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_money]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  564. case "testnchar": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_nchar]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  565. case "testntext": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_ntext]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  566. case "testnvarchar": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_nvarchar]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  567. case "testreal": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_real]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  568. case "testsmalldatetime": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_smalldatetime]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  569. case "testsmallint": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_smallint]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  570. case "testsmallmoney": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_smallmoney]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  571. case "testtext": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_text]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  572. case "testtime": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_time]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  573. case "testtinyint": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_tinyint]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  574. case "testuniqueidentifier": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_uniqueidentifier]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  575. case "testvarbinary": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_varbinary]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  576. case "testvarchar": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_varchar]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  577. case "testxml": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[test_xml]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  578. case "testcalculated": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[TestCalculated]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  579. case "varcharmax": orderByClause += "[" + (from x in fieldList where x.Alias.ToLower() == fieldItem.Field.ToString().ToLower() select x).FirstOrDefault().Table + "].[varcharmax]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  580. case "createddate": orderByClause += "[t0].[created_date]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  581. case "createdby": orderByClause += "[t0].[created_by]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  582. case "modifieddate": orderByClause += "[t0].[modified_date]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  583. case "modifiedby": orderByClause += "[t0].[modified_by]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  584. case "timestamp": orderByClause += "[t0].[time_stamp]" + (fieldItem.Ascending ? string.Empty : " DESC"); break;
  585. default: throw new Exception("The order by clause is not valid.");
  586. }
  587. }
  588. //Get the primary key for predictable sorts
  589. string primarySortKey = string.Empty;
  590. primarySortKey = "[t0].[guid_id]";
  591. sb.AppendLine(", ROW_NUMBER() OVER (ORDER BY " + orderByClause + ((primarySortKey == string.Empty) || ((isPrimary && (!string.IsNullOrEmpty(primarySortKey)))) ? string.Empty : ", " + primarySortKey) + ") AS Row");
  592. //Calculate the FROM clause
  593. index = 0;
  594. sb.Append("FROM ");
  595. foreach (LinqSQLFromClause fromClause in fromLinkList)
  596. {
  597. sb.Append("[" + fromClause.Schema + "].[" + fromClause.TableName + "] AS [" + fromClause.Alias + "] ");
  598. if (optimizer.NoLocking) sb.Append("WITH (NOLOCK)");
  599. if (!string.IsNullOrEmpty(fromClause.LinkClause)) sb.Append(fromClause.LinkClause + " ");
  600. if (index < fromLinkList.Count - 1)
  601. {
  602. sb.AppendLine();
  603. sb.Append("LEFT OUTER JOIN ");
  604. }
  605. index++;
  606. }
  607. sb.AppendLine();
  608. //Calculate the WHERE clause
  609. if (!string.IsNullOrEmpty(whereClause))
  610. {
  611. foreach (LinqSQLFromClause fromClause in fromLinkList)
  612. {
  613. //Only process table that were original and not inserted above
  614. if (fromClause.AnchorAlias == string.Empty)
  615. {
  616. whereClause = LinqSQLParser.GetRemappedLinqSql(fromClause, whereClause, fromLinkList, LinqSQLParser.ObjectTypeConstants.Table);
  617. }
  618. }
  619. sb.Append("WHERE " + whereClause);
  620. }
  621. sb.AppendLine(") AS [t0]");
  622. sb.AppendLine("WHERE (Row >= " + (((paging2.PageIndex - 1) * paging2.RecordsperPage) + 1) + ") AND (Row <= " + (paging2.PageIndex * paging2.RecordsperPage) + ")");
  623. return sb.ToString();
  624. }
  625. #endregion
  626. /// <summary>
  627. /// Persists this collection to store.
  628. /// </summary>
  629. public override void Persist()
  630. {
  631. try
  632. {
  633. foreach (ManyTypes item in this)
  634. {
  635. if (item.wrappedClass.RowState != DataRowState.Unchanged)
  636. item.OnValidate(new BusinessObjectEventArgs(item));
  637. }
  638. lock (wrappedClass.SubDomain)
  639. {
  640. wrappedClass.Persist();
  641. }
  642. }
  643. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  644. 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; }
  645. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  646. }
  647. /// <summary>
  648. /// Select all objects from store.
  649. /// </summary>
  650. public static ManyTypesCollection RunSelect()
  651. {
  652. return RunSelect(ConfigurationValues.GetInstance().Modifier);
  653. }
  654. /// <summary>
  655. /// Select all objects from store.
  656. /// </summary>
  657. public static ManyTypesCollection RunSelect(string modifier)
  658. {
  659. try
  660. {
  661. var returnVal = new ManyTypesCollection(DomainManyTypesCollection.RunSelect(modifier));
  662. return returnVal;
  663. }
  664. catch (System.Data.DBConcurrencyException dbcex) { throw new Widgetsphere.Core.Exceptions.ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
  665. 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; }
  666. catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
  667. }
  668. /// <summary>
  669. /// Using the specified Where expression, execute a query against the database to return a result set
  670. /// </summary>
  671. /// <param name="where">The expression that determines the records selected</param>
  672. public static ManyTypesCollection RunSelect(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where)
  673. {
  674. return RunSelect(where, ConfigurationValues.GetInstance().Modifier);
  675. }
  676. /// <summary>
  677. /// Using the specified Where expression, execute a query against the database to return a result set
  678. /// </summary>
  679. /// <param name="where">The expression that determines the records selected</param>
  680. /// <param name="modifier">The modified audit trail</param>
  681. public static ManyTypesCollection RunSelect(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where, string modifier)
  682. {
  683. return RunSelect(where, new QueryOptimizer(), modifier);
  684. }
  685. /// <summary>
  686. /// Using the specified Where expression, execute a query against the database to return a result set
  687. /// </summary>
  688. /// <param name="where">The expression that determines the records selected</param>
  689. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  690. /// <param name="modifier">The modified audit trail</param>
  691. public static ManyTypesCollection RunSelect(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where, Widgetsphere.Core.DataAccess.QueryOptimizer optimizer, string modifier)
  692. {
  693. var subDomain = new SubDomain(modifier);
  694. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  695. var template = dc.GetTable<ManyTypesQuery>();
  696. var cmd = BusinessCollectionPersistableBase.GetCommand<ManyTypesQuery>(dc, template, where);
  697. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  698. var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.Table);
  699. cmd.CommandText = parser.GetSQL(optimizer);
  700. dc.Connection.Open();
  701. var startTime = DateTime.Now;
  702. var result = dc.Translate<ManyTypesQuery>(cmd.ExecuteReader());
  703. var endTime = DateTime.Now;
  704. optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
  705. var retval = subDomain.GetCollection<ManyTypesCollection>();
  706. var pkList = new HashSet<string>();
  707. foreach (var item in result)
  708. {
  709. var pk = item.SinglePrimaryKeyValue();
  710. if (!pkList.Contains(pk))
  711. {
  712. pkList.Add(pk);
  713. var newItem = retval.NewItem(item.GuidId);
  714. LoadDataRow(item, newItem);
  715. retval.AddItem(newItem);
  716. }
  717. }
  718. retval.wrappedClass.AcceptChanges();
  719. retval.wrappedClass.EndLoadData();
  720. dc.Connection.Close();
  721. return retval;
  722. }
  723. /// <summary>
  724. /// Using the specified Where expression, execute a query against the database to return a result set
  725. /// </summary>
  726. /// <param name="where">The expression that determines the records selected</param>
  727. /// <param name="paging">The paging object to determine how the results are paged.</param>
  728. public static ManyTypesCollection RunSelect(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where, Acme.TestModel.Business.Objects.ManyTypesPaging paging)
  729. {
  730. return RunSelect(where, paging, ConfigurationValues.GetInstance().Modifier);
  731. }
  732. /// <summary>
  733. /// Using the specified Where expression, execute a query against the database to return a result set
  734. /// </summary>
  735. /// <param name="where">The expression that determines the records selected</param>
  736. /// <param name="paging">The paging object to determine how the results are paged.</param>
  737. /// <param name="modifier">The modified audit trail</param>
  738. public static ManyTypesCollection RunSelect(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where, Acme.TestModel.Business.Objects.ManyTypesPaging paging, string modifier)
  739. {
  740. return RunSelect(where, paging, new QueryOptimizer(), modifier);
  741. }
  742. /// <summary>
  743. /// Using the specified Where expression, execute a query against the database to return a result set
  744. /// </summary>
  745. /// <param name="where">The expression that determines the records selected</param>
  746. /// <param name="paging">The paging object to determine how the results are paged.</param>
  747. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  748. /// <param name="modifier">The modified audit trail</param>
  749. public static ManyTypesCollection RunSelect(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where, Acme.TestModel.Business.Objects.ManyTypesPaging paging, Widgetsphere.Core.DataAccess.QueryOptimizer optimizer, string modifier)
  750. {
  751. if (paging == null) throw new Exception("The paging object cannot be null.");
  752. var subDomain = new SubDomain(modifier);
  753. var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);
  754. var template = dc.GetTable<ManyTypesQuery>();
  755. var cmd = BusinessCollectionPersistableBase.GetCommand<ManyTypesQuery>(dc, template, where);
  756. cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;
  757. var parser = LinqSQLParser.Create(cmd.CommandText, paging, LinqSQLParser.ObjectTypeConstants.Table);
  758. cmd.CommandText = parser.GetSQL(optimizer);
  759. dc.Connection.Open();
  760. var startTime = DateTime.Now;
  761. var result = dc.Translate<ManyTypesQuery>(cmd.ExecuteReader());
  762. var endTime = DateTime.Now;
  763. optimizer.TotalMilliseconds = (long)endTime.Subtract(startTime).TotalMilliseconds;
  764. var retval = subDomain.GetCollection<ManyTypesCollection>();
  765. var pkList = new HashSet<string>();
  766. foreach (var item in result)
  767. {
  768. var pk = item.SinglePrimaryKeyValue();
  769. if (!pkList.Contains(pk))
  770. {
  771. pkList.Add(pk);
  772. var newItem = retval.NewItem(item.GuidId);
  773. LoadDataRow(item, newItem);
  774. retval.AddItem(newItem);
  775. }
  776. }
  777. retval.wrappedClass.AcceptChanges();
  778. retval.wrappedClass.EndLoadData();
  779. dc.Connection.Close();
  780. paging.RecordCount = GetCount(where);
  781. return retval;
  782. }
  783. private static void LoadDataRow(ManyTypesQuery item, ManyTypes newItem)
  784. {
  785. newItem.wrappedClass["varcharmax"] = item.Varcharmax;
  786. newItem.wrappedClass["TestCalculated"] = StringHelper.ConvertToDatabase(item.Testcalculated);
  787. newItem.wrappedClass["test_xml"] = item.TestXml;
  788. newItem.wrappedClass["test_datetimeoffset"] = item.TestDatetimeoffset;
  789. newItem.wrappedClass["test_datetime2"] = item.TestDatetime2;
  790. newItem.wrappedClass["test_time"] = item.TestTime;
  791. newItem.wrappedClass["test_date"] = item.TestDate;
  792. newItem.wrappedClass["test_varbinary"] = item.TestVarbinary;
  793. newItem.wrappedClass["test_tinyint"] = item.TestTinyint;
  794. newItem.wrappedClass["test_text"] = item.TestText;
  795. newItem.wrappedClass["test_smallmoney"] = item.TestSmallmoney;
  796. newItem.wrappedClass["test_smallint"] = item.TestSmallint;
  797. newItem.wrappedClass["test_smalldatetime"] = item.TestSmalldatetime;
  798. newItem.wrappedClass["test_uniqueidentifier"] = item.TestUniqueidentifier;
  799. newItem.wrappedClass["test_real"] = item.TestReal;
  800. newItem.wrappedClass["test_nvarchar"] = item.TestNvarchar;
  801. newItem.wrappedClass["test_ntext"] = item.TestNtext;
  802. newItem.wrappedClass["test_nchar"] = item.TestNchar;
  803. newItem.wrappedClass["test_money"] = item.TestMoney;
  804. newItem.wrappedClass["test_int"] = item.TestInt;
  805. newItem.wrappedClass["test_image"] = item.TestImage;
  806. newItem.wrappedClass["test_float"] = item.TestFloat;
  807. newItem.wrappedClass["test_decimal"] = item.TestDecimal;
  808. newItem.wrappedClass["test_datetime"] = item.TestDatetime;
  809. newItem.wrappedClass["test_char"] = item.TestChar;
  810. newItem.wrappedClass["test_bit"] = item.TestBit;
  811. newItem.wrappedClass["test_binary"] = item.TestBinary;
  812. newItem.wrappedClass["test_bigint"] = item.TestBigint;
  813. newItem.wrappedClass["test_varchar"] = item.TestVarchar;
  814. newItem.wrappedClass["guid_id"] = item.GuidId;
  815. newItem.wrappedClass["CreatedDate"] = StringHelper.ConvertToDatabase(item.CreatedDate);
  816. newItem.wrappedClass["CreatedBy"] = StringHelper.ConvertToDatabase(item.CreatedBy);
  817. newItem.wrappedClass["ModifiedDate"] = StringHelper.ConvertToDatabase(item.ModifiedDate);
  818. newItem.wrappedClass["ModifiedBy"] = StringHelper.ConvertToDatabase(item.ModifiedBy);
  819. newItem.wrappedClass["TimeStamp"] = item.TimeStamp;
  820. }
  821. /// <summary>
  822. /// Get the maximum value of the field for all objects
  823. /// </summary>
  824. /// <param name="select">The field to aggregate</param>
  825. public static int? GetMax(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, int>> select)
  826. {
  827. return GetMax(select, x => true);
  828. }
  829. /// <summary>
  830. /// Get the maximum value of the field in the set of records that match the Where condition
  831. /// </summary>
  832. /// <param name="select">The field to aggregate</param>
  833. /// <param name="where">The expression that determines the records selected</param>
  834. public static int? GetMax(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, int>> select, Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where)
  835. {
  836. return GetMax(select, where, new QueryOptimizer());
  837. }
  838. /// <summary>
  839. /// Get the maximum value of the field in the set of records that match the Where condition
  840. /// </summary>
  841. /// <param name="select">The field to aggregate</param>
  842. /// <param name="where">The expression that determines the records selected</param>
  843. /// <param name="optimizer">An object to specify querying parameters and return profiling information</param>
  844. public static int? GetMax(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, int>> select, Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, bool>> where, Widgetsphere.Core.DataAccess.QueryOptimizer optimizer)
  845. {
  846. return BusinessObjectQuery<ManyTypes, ManyTypesQuery, int>.GetMax(select, where, optimizer, "MANY_TYPES", GetDatabaseFieldName, LinqSQLParser.ObjectTypeConstants.Table);
  847. }
  848. /// <summary>
  849. /// Get the maximum value of the field for all objects
  850. /// </summary>
  851. /// <param name="select">The field to aggregate</param>
  852. public static int? GetMax(Expression<Func<Acme.TestModel.Business.LINQ.ManyTypesQuery, int?>> select)
  853. {
  854. return GetMax(select, x => true);
  855. }
  856. /// <summary>
  857. /// Get the maximum value of the field in the set of records that match the Where condition
  858. /// </summary>
  859. /// <param name="select">The field to aggregate</param>
  860. /// <param name="where">The expression that determines the records selected</param>
  861. public st

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