diff --git a/DynamORM/DynamicColumn.cs b/DynamORM/DynamicColumn.cs
index 9783c35..e87b61d 100644
--- a/DynamORM/DynamicColumn.cs
+++ b/DynamORM/DynamicColumn.cs
@@ -145,6 +145,12 @@ namespace DynamORM
/// Gets or sets a value indicating whether set parameters for null values.
public bool VirtualColumn { get; set; }
+ /// Gets or sets schema representation of a column.
+ /// Woraround to providers issues which sometimes pass wrong
+ /// data o schema. For example decimal has precission of 255 in sql
+ /// server.
+ public DynamicSchemaColumn? Schema { get; set; }
+
#endregion Properties
#region Query creation helpers
@@ -297,6 +303,8 @@ namespace DynamORM
#endregion Order
+ #region Other
+
/// Helper method setting
///
/// to provided name.
@@ -330,6 +338,44 @@ namespace DynamORM
return this;
}
+ /// Sets the begin block flag.
+ /// If set to true [begin].
+ /// Returns self.
+ public DynamicColumn SetBeginBlock(bool begin)
+ {
+ BeginBlock = begin;
+ return this;
+ }
+
+ /// Sets the end block flag.
+ /// If set to true [end].
+ /// Returns self.
+ public DynamicColumn SetEndBlock(bool end)
+ {
+ EndBlock = end;
+ return this;
+ }
+
+ /// Sets the or flag.
+ /// If set to true [or].
+ /// Returns self.
+ public DynamicColumn SetOr(bool or)
+ {
+ Or = or;
+ return this;
+ }
+
+ /// Sets the virtual column.
+ /// If set to true [virt].
+ /// Returns self.
+ public DynamicColumn SetVirtualColumn(bool virt)
+ {
+ VirtualColumn = virt;
+ return this;
+ }
+
+ #endregion Other
+
#endregion Query creation helpers
#region Parsing
diff --git a/DynamORM/DynamicDatabase.cs b/DynamORM/DynamicDatabase.cs
index a5eae22..7995a86 100644
--- a/DynamORM/DynamicDatabase.cs
+++ b/DynamORM/DynamicDatabase.cs
@@ -287,7 +287,7 @@ namespace DynamORM
{
using (var rdr = cmd
.SetCommand(string.Format("SELECT * FROM {0} WHERE 1 = 0", DecorateName(table)))
- .ExecuteReader(CommandBehavior.SchemaOnly))
+ .ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo))
foreach (DataRow col in rdr.GetSchemaTable().Rows)
{
var c = col.RowToDynamicUpper();
diff --git a/DynamORM/DynamicExtensions.cs b/DynamORM/DynamicExtensions.cs
index 532ddfa..b5a7e48 100644
--- a/DynamORM/DynamicExtensions.cs
+++ b/DynamORM/DynamicExtensions.cs
@@ -213,15 +213,40 @@ namespace DynamORM
return cmd;
}
+ /// Extension method for adding in a bunch of parameters.
+ /// Command to handle.
+ /// Database object required to get proper formatting.
+ /// Items to add in an expando object.
+ /// Returns edited instance.
+ public static IDbCommand AddParameters(this IDbCommand cmd, DynamicDatabase database, ExpandoObject args)
+ {
+ if (args != null && args.Count() > 0)
+ foreach (var item in args.ToDictionary())
+ cmd.AddParameter(database, item.Key, item.Value);
+
+ return cmd;
+ }
+
/// Extension for adding single parameter determining only type of object.
/// Command to handle.
/// Database object required to get proper formatting.
/// Items to add.
/// Returns edited instance.
public static IDbCommand AddParameter(this IDbCommand cmd, DynamicDatabase database, object item)
+ {
+ return cmd.AddParameter(database, database.GetParameterName(cmd.Parameters.Count), item);
+ }
+
+ /// Extension for adding single parameter determining only type of object.
+ /// Command to handle.
+ /// Database object required to get proper formatting.
+ /// Name of parameter.
+ /// Items to add.
+ /// Returns edited instance.
+ public static IDbCommand AddParameter(this IDbCommand cmd, DynamicDatabase database, string name, object item)
{
var p = cmd.CreateParameter();
- p.ParameterName = database.GetParameterName(cmd.Parameters.Count);
+ p.ParameterName = name;
if (item == null)
p.Value = DBNull.Value;
@@ -255,7 +280,7 @@ namespace DynamORM
var p = cmd.CreateParameter();
p.ParameterName = builder.DynamicTable.Database.GetParameterName(cmd.Parameters.Count);
- var col = builder.Schema.TryGetNullable(item.ColumnName.ToLower());
+ var col = item.Schema ?? builder.Schema.TryGetNullable(item.ColumnName.ToLower());
if (col.HasValue)
{
@@ -268,6 +293,7 @@ namespace DynamORM
p.Scale = col.Value.Scale;
// Quick fix - review that
+ // Quick fix 2 - use item.Schema in that case
if (p.Scale > p.Precision)
p.Scale = 4;
}
diff --git a/DynamORM/DynamicTable.cs b/DynamORM/DynamicTable.cs
index 08050df..69256cd 100644
--- a/DynamORM/DynamicTable.cs
+++ b/DynamORM/DynamicTable.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
+using System.Data;
using System.Dynamic;
using System.Linq;
using DynamORM.Builders;
@@ -311,8 +312,8 @@ namespace DynamORM
/// Enumerate the reader and yield the result.
/// Sql query containing numered parameters in format provided by
- /// methods. Also names should be formated with
- /// method.
+ /// methods. Also names should be formated with
+ /// method.
/// Arguments (parameters).
/// Enumerator of objects expanded from query.
public virtual IEnumerable Query(string sql, params object[] args)
@@ -354,8 +355,8 @@ namespace DynamORM
/// Returns a single result.
/// Sql query containing numered parameters in format provided by
- /// methods. Also names should be formated with
- /// method.
+ /// methods. Also names should be formated with
+ /// method.
/// Arguments (parameters).
/// Result of a query.
public virtual object Scalar(string sql, params object[] args)
@@ -383,10 +384,28 @@ namespace DynamORM
}
}
+ /// Execute stored procedure.
+ /// Name of stored procedure to execute.
+ /// Arguments (parameters) in form of expando object.
+ /// Number of affected rows.
+ public virtual int Procedure(string procName, ExpandoObject args = null)
+ {
+ if ((Database.Options & DynamicDatabaseOptions.SupportStoredProcedures) != DynamicDatabaseOptions.SupportStoredProcedures)
+ throw new InvalidOperationException("Database connection desn't support stored procedures.");
+
+ using (var con = Database.Open())
+ using (var cmd = con.CreateCommand())
+ {
+ return cmd
+ .SetCommand(CommandType.StoredProcedure, procName).AddParameters(Database, args)
+ .ExecuteNonQuery();
+ }
+ }
+
/// Execute non query.
/// Sql query containing numered parameters in format provided by
- /// methods. Also names should be formated with
- /// method.
+ /// methods. Also names should be formated with
+ /// method.
/// Arguments (parameters).
/// Number of affected rows.
public virtual int Execute(string sql, params object[] args)