Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using System.Data.Linq;
11 : using Cqrs.Entities;
12 :
13 : namespace Cqrs.DataStores
14 : {
15 : /// <summary>
16 : /// A collection of extension methods for <see cref="Table{TData}"/>
17 : /// </summary>
18 : public static class SqlDataStoreExtension
19 1 : {
20 : /*
21 : public static int DeleteBatch<TEntity>(this Table<TEntity> table, IQueryable<TEntity> entities)
22 : where TEntity : class
23 : {
24 : DbCommand delete = table.GetDeleteBatchCommand<TEntity>(entities);
25 :
26 : var parameters =
27 : from p in delete.Parameters.Cast<DbParameter>()
28 : select p.Value;
29 :
30 : return table.Context.ExecuteCommand(
31 : delete.CommandText,
32 : parameters.ToArray());
33 : }
34 :
35 : public static int UpdateBatch<TEntity>(this Table<TEntity> table, IQueryable<TEntity> entities, object evaluator)
36 : where TEntity : class
37 : {
38 : DbCommand update = table.GetUpdateBatchCommand<TEntity>(entities, evaluator);
39 :
40 : var parameters =
41 : from p in update.Parameters.Cast<DbParameter>()
42 : select p.Value;
43 :
44 : return table.Context.ExecuteCommand(
45 : update.CommandText,
46 : parameters.ToArray());
47 : }
48 : */
49 :
50 : /// <summary>
51 : /// Calls the TRUNCATE SQL command on the <see cref="Table{TEntity}"/>.
52 : /// </summary>
53 : /// <typeparam name="TEntity">The <see cref="Type"/> of <see cref="IEntity"/> to truncate all data of.</typeparam>
54 : /// <param name="table">The <see cref="Table{TEntity}"/> to truncate all data of.</param>
55 1 : public static void Truncate<TEntity>(this Table<TEntity> table) where TEntity : class
56 : {
57 : Type rowType = table.GetType().GetGenericArguments()[0];
58 : string tableName = table.Context.Mapping.GetTable(rowType).TableName;
59 : const string sqlCommand = "TRUNCATE TABLE {0}";
60 : table.Context.ExecuteCommand(string.Format(sqlCommand, tableName));
61 : }
62 : }
63 : }
|