This commit is contained in:
@@ -1840,9 +1840,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to insert.</param>
|
/// <param name="e">Enumerable containing instances of objects to insert.</param>
|
||||||
/// <returns>Number of inserted rows.</returns>
|
/// <returns>Number of inserted rows.</returns>
|
||||||
public virtual int Insert<T>(IEnumerable<T> e) where T : class
|
public virtual int Insert<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return Insert(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk insert objects into database.</summary>
|
||||||
|
/// <param name="t">Type of objects to insert.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to insert.</param>
|
||||||
|
/// <returns>Number of inserted rows.</returns>
|
||||||
|
public virtual int Insert(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -1871,9 +1880,9 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchInsert<T>(mapper, cmd, parameters);
|
PrepareBatchInsert(t, mapper, cmd, parameters);
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -1938,9 +1947,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to update.</param>
|
/// <param name="e">Enumerable containing instances of objects to update.</param>
|
||||||
/// <returns>Number of updated rows.</returns>
|
/// <returns>Number of updated rows.</returns>
|
||||||
public virtual int Update<T>(IEnumerable<T> e) where T : class
|
public virtual int Update<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return Update(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk update objects in database.</summary>
|
||||||
|
/// <param name="T">Type of objects to update.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to update.</param>
|
||||||
|
/// <returns>Number of updated rows.</returns>
|
||||||
|
public virtual int Update(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -1969,9 +1987,9 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchUpdate<T>(mapper, cmd, parameters);
|
PrepareBatchUpdate(t, mapper, cmd, parameters);
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -2004,9 +2022,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to update or insert.</param>
|
/// <param name="e">Enumerable containing instances of objects to update or insert.</param>
|
||||||
/// <returns>Number of updated or inserted rows.</returns>
|
/// <returns>Number of updated or inserted rows.</returns>
|
||||||
public virtual int UpdateOrInsert<T>(IEnumerable<T> e) where T : class
|
public virtual int UpdateOrInsert<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return UpdateOrInsert(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk update or insert objects into database.</summary>
|
||||||
|
/// <param name="t">Type of objects to update or insert.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to update or insert.</param>
|
||||||
|
/// <returns>Number of updated or inserted rows.</returns>
|
||||||
|
public virtual int UpdateOrInsert(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -2038,7 +2065,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchUpdate<T>(mapper, cmdUp, parametersUp);
|
PrepareBatchUpdate(t, mapper, cmdUp, parametersUp);
|
||||||
|
|
||||||
#endregion Update
|
#endregion Update
|
||||||
|
|
||||||
@@ -2063,11 +2090,11 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchInsert<T>(mapper, cmdIn, parametersIn);
|
PrepareBatchInsert(t, mapper, cmdIn, parametersIn);
|
||||||
|
|
||||||
#endregion Insert
|
#endregion Insert
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parametersUp)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parametersUp)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -2141,9 +2168,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to delete.</param>
|
/// <param name="e">Enumerable containing instances of objects to delete.</param>
|
||||||
/// <returns>Number of deleted rows.</returns>
|
/// <returns>Number of deleted rows.</returns>
|
||||||
public virtual int Delete<T>(IEnumerable<T> e) where T : class
|
public virtual int Delete<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return Delete(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk delete objects in database.</summary>
|
||||||
|
/// <param name="t">Type of objects to delete.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to delete.</param>
|
||||||
|
/// <returns>Number of deleted rows.</returns>
|
||||||
|
public virtual int Delete(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -2172,9 +2208,9 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchDelete<T>(mapper, cmd, parameters);
|
PrepareBatchDelete(t, mapper, cmd, parameters);
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -2203,13 +2239,18 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareBatchInsert<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
private void PrepareBatchInsert<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
PrepareBatchInsert(typeof(T), mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchInsert(Type t, DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
{
|
{
|
||||||
DynamicPropertyInvoker currentprop = null;
|
DynamicPropertyInvoker currentprop = null;
|
||||||
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema<T>();
|
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema(t);
|
||||||
int ord = 0;
|
int ord = 0;
|
||||||
|
|
||||||
IDynamicInsertQueryBuilder ib = Insert<T>()
|
IDynamicInsertQueryBuilder ib = Insert(t)
|
||||||
.SetVirtualMode(true)
|
.SetVirtualMode(true)
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
.CreateParameterAction((p, cp) =>
|
.CreateParameterAction((p, cp) =>
|
||||||
@@ -2250,13 +2291,18 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareBatchUpdate<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
private void PrepareBatchUpdate<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
PrepareBatchUpdate(typeof(T), mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchUpdate(Type t, DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
{
|
{
|
||||||
DynamicPropertyInvoker currentprop = null;
|
DynamicPropertyInvoker currentprop = null;
|
||||||
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema<T>();
|
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema(t);
|
||||||
int ord = 0;
|
int ord = 0;
|
||||||
|
|
||||||
IDynamicUpdateQueryBuilder ib = Update<T>()
|
IDynamicUpdateQueryBuilder ib = Update(t)
|
||||||
.SetVirtualMode(true)
|
.SetVirtualMode(true)
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
.CreateParameterAction((p, cp) =>
|
.CreateParameterAction((p, cp) =>
|
||||||
@@ -2323,13 +2369,18 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareBatchDelete<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
private void PrepareBatchDelete<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
PrepareBatchDelete(typeof(T), mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchDelete(Type t, DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
{
|
{
|
||||||
DynamicPropertyInvoker currentprop = null;
|
DynamicPropertyInvoker currentprop = null;
|
||||||
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema<T>();
|
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema(t);
|
||||||
int ord = 0;
|
int ord = 0;
|
||||||
|
|
||||||
IDynamicDeleteQueryBuilder ib = Delete<T>()
|
IDynamicDeleteQueryBuilder ib = Delete(t)
|
||||||
.SetVirtualMode(true)
|
.SetVirtualMode(true)
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
.CreateParameterAction((p, cp) =>
|
.CreateParameterAction((p, cp) =>
|
||||||
@@ -4791,7 +4842,7 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
Type generic = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
Type generic = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
||||||
|
|
||||||
if (generic != null && generic.Equals(typeof(Nullable<>)) && type.IsClass)
|
if (generic != null && generic.Equals(typeof(Nullable<>)) && (type.IsClass || type.IsValueType || type.IsEnum))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -13322,6 +13373,9 @@ namespace DynamORM
|
|||||||
|
|
||||||
Column = attr;
|
Column = attr;
|
||||||
|
|
||||||
|
if (attr != null && attr.AllowNull && Type.IsNullableType())
|
||||||
|
attr.AllowNull = false;
|
||||||
|
|
||||||
if (property.CanRead)
|
if (property.CanRead)
|
||||||
Get = CreateGetter(property);
|
Get = CreateGetter(property);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
@@ -379,9 +380,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to insert.</param>
|
/// <param name="e">Enumerable containing instances of objects to insert.</param>
|
||||||
/// <returns>Number of inserted rows.</returns>
|
/// <returns>Number of inserted rows.</returns>
|
||||||
public virtual int Insert<T>(IEnumerable<T> e) where T : class
|
public virtual int Insert<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return Insert(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk insert objects into database.</summary>
|
||||||
|
/// <param name="t">Type of objects to insert.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to insert.</param>
|
||||||
|
/// <returns>Number of inserted rows.</returns>
|
||||||
|
public virtual int Insert(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -410,9 +420,9 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchInsert<T>(mapper, cmd, parameters);
|
PrepareBatchInsert(t, mapper, cmd, parameters);
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -477,9 +487,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to update.</param>
|
/// <param name="e">Enumerable containing instances of objects to update.</param>
|
||||||
/// <returns>Number of updated rows.</returns>
|
/// <returns>Number of updated rows.</returns>
|
||||||
public virtual int Update<T>(IEnumerable<T> e) where T : class
|
public virtual int Update<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return Update(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk update objects in database.</summary>
|
||||||
|
/// <param name="T">Type of objects to update.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to update.</param>
|
||||||
|
/// <returns>Number of updated rows.</returns>
|
||||||
|
public virtual int Update(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -508,9 +527,9 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchUpdate<T>(mapper, cmd, parameters);
|
PrepareBatchUpdate(t, mapper, cmd, parameters);
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -543,9 +562,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to update or insert.</param>
|
/// <param name="e">Enumerable containing instances of objects to update or insert.</param>
|
||||||
/// <returns>Number of updated or inserted rows.</returns>
|
/// <returns>Number of updated or inserted rows.</returns>
|
||||||
public virtual int UpdateOrInsert<T>(IEnumerable<T> e) where T : class
|
public virtual int UpdateOrInsert<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return UpdateOrInsert(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk update or insert objects into database.</summary>
|
||||||
|
/// <param name="t">Type of objects to update or insert.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to update or insert.</param>
|
||||||
|
/// <returns>Number of updated or inserted rows.</returns>
|
||||||
|
public virtual int UpdateOrInsert(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -577,7 +605,7 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchUpdate<T>(mapper, cmdUp, parametersUp);
|
PrepareBatchUpdate(t, mapper, cmdUp, parametersUp);
|
||||||
|
|
||||||
#endregion Update
|
#endregion Update
|
||||||
|
|
||||||
@@ -602,11 +630,11 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchInsert<T>(mapper, cmdIn, parametersIn);
|
PrepareBatchInsert(t, mapper, cmdIn, parametersIn);
|
||||||
|
|
||||||
#endregion Insert
|
#endregion Insert
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parametersUp)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parametersUp)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -680,9 +708,18 @@ namespace DynamORM
|
|||||||
/// <param name="e">Enumerable containing instances of objects to delete.</param>
|
/// <param name="e">Enumerable containing instances of objects to delete.</param>
|
||||||
/// <returns>Number of deleted rows.</returns>
|
/// <returns>Number of deleted rows.</returns>
|
||||||
public virtual int Delete<T>(IEnumerable<T> e) where T : class
|
public virtual int Delete<T>(IEnumerable<T> e) where T : class
|
||||||
|
{
|
||||||
|
return Delete(typeof(T), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Bulk delete objects in database.</summary>
|
||||||
|
/// <param name="t">Type of objects to delete.</param>
|
||||||
|
/// <param name="e">Enumerable containing instances of objects to delete.</param>
|
||||||
|
/// <returns>Number of deleted rows.</returns>
|
||||||
|
public virtual int Delete(Type t, IEnumerable e)
|
||||||
{
|
{
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(typeof(T));
|
DynamicTypeMap mapper = DynamicMapperCache.GetMapper(t);
|
||||||
|
|
||||||
if (mapper != null)
|
if (mapper != null)
|
||||||
{
|
{
|
||||||
@@ -711,9 +748,9 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
PrepareBatchDelete<T>(mapper, cmd, parameters);
|
PrepareBatchDelete(t, mapper, cmd, parameters);
|
||||||
|
|
||||||
foreach (T o in e)
|
foreach (var o in e)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
foreach (KeyValuePair<IDbDataParameter, DynamicPropertyInvoker> m in parameters)
|
||||||
m.Key.Value = m.Value.Get(o);
|
m.Key.Value = m.Value.Get(o);
|
||||||
@@ -742,13 +779,18 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareBatchInsert<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
private void PrepareBatchInsert<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
PrepareBatchInsert(typeof(T), mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchInsert(Type t, DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
{
|
{
|
||||||
DynamicPropertyInvoker currentprop = null;
|
DynamicPropertyInvoker currentprop = null;
|
||||||
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema<T>();
|
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema(t);
|
||||||
int ord = 0;
|
int ord = 0;
|
||||||
|
|
||||||
IDynamicInsertQueryBuilder ib = Insert<T>()
|
IDynamicInsertQueryBuilder ib = Insert(t)
|
||||||
.SetVirtualMode(true)
|
.SetVirtualMode(true)
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
.CreateParameterAction((p, cp) =>
|
.CreateParameterAction((p, cp) =>
|
||||||
@@ -789,13 +831,18 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareBatchUpdate<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
private void PrepareBatchUpdate<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
PrepareBatchUpdate(typeof(T), mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchUpdate(Type t, DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
{
|
{
|
||||||
DynamicPropertyInvoker currentprop = null;
|
DynamicPropertyInvoker currentprop = null;
|
||||||
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema<T>();
|
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema(t);
|
||||||
int ord = 0;
|
int ord = 0;
|
||||||
|
|
||||||
IDynamicUpdateQueryBuilder ib = Update<T>()
|
IDynamicUpdateQueryBuilder ib = Update(t)
|
||||||
.SetVirtualMode(true)
|
.SetVirtualMode(true)
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
.CreateParameterAction((p, cp) =>
|
.CreateParameterAction((p, cp) =>
|
||||||
@@ -862,13 +909,18 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareBatchDelete<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
private void PrepareBatchDelete<T>(DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
|
{
|
||||||
|
PrepareBatchDelete(typeof(T), mapper, cmd, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareBatchDelete(Type t, DynamicTypeMap mapper, IDbCommand cmd, Dictionary<IDbDataParameter, DynamicPropertyInvoker> parameters)
|
||||||
{
|
{
|
||||||
DynamicPropertyInvoker currentprop = null;
|
DynamicPropertyInvoker currentprop = null;
|
||||||
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
Dictionary<string, DynamicPropertyInvoker> temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema<T>();
|
Dictionary<string, DynamicSchemaColumn> schema = this.GetSchema(t);
|
||||||
int ord = 0;
|
int ord = 0;
|
||||||
|
|
||||||
IDynamicDeleteQueryBuilder ib = Delete<T>()
|
IDynamicDeleteQueryBuilder ib = Delete(t)
|
||||||
.SetVirtualMode(true)
|
.SetVirtualMode(true)
|
||||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||||
.CreateParameterAction((p, cp) =>
|
.CreateParameterAction((p, cp) =>
|
||||||
|
|||||||
@@ -1322,7 +1322,7 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
Type generic = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
Type generic = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
||||||
|
|
||||||
if (generic != null && generic.Equals(typeof(Nullable<>)) && type.IsClass)
|
if (generic != null && generic.Equals(typeof(Nullable<>)) && (type.IsClass || type.IsValueType || type.IsEnum))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -111,6 +111,9 @@ namespace DynamORM.Mapper
|
|||||||
|
|
||||||
Column = attr;
|
Column = attr;
|
||||||
|
|
||||||
|
if (attr != null && attr.AllowNull && Type.IsNullableType())
|
||||||
|
attr.AllowNull = false;
|
||||||
|
|
||||||
if (property.CanRead)
|
if (property.CanRead)
|
||||||
Get = CreateGetter(property);
|
Get = CreateGetter(property);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user