U4-9107 Change BulkInsertRecords to use BulkCopy or TableDirect (SQLCE)

This commit is contained in:
Shannon
2016-10-25 12:29:17 +02:00
parent 74a5bf5503
commit dadcbc8b31
17 changed files with 4901 additions and 284 deletions

View File

@@ -1,4 +1,6 @@
using System;
using System.Data;
using System.Linq;
using Umbraco.Core.Persistence.Querying;
namespace Umbraco.Core.Persistence.SqlSyntax
@@ -133,5 +135,111 @@ namespace Umbraco.Core.Persistence.SqlSyntax
throw new ArgumentOutOfRangeException("columnType");
}
}
/// <summary>
/// This uses a the DbTypeMap created and custom mapping to resolve the SqlDbType
/// </summary>
/// <param name="clrType"></param>
/// <returns></returns>
public virtual SqlDbType GetSqlDbType(Type clrType)
{
var dbType = DbTypeMap.ColumnDbTypeMap.First(x => x.Key == clrType).Value;
return GetSqlDbType(dbType);
}
/// <summary>
/// Returns the mapped SqlDbType for the DbType specified
/// </summary>
/// <param name="dbType"></param>
/// <returns></returns>
public virtual SqlDbType GetSqlDbType(DbType dbType)
{
var sqlDbType = SqlDbType.NVarChar;
//SEE: https://msdn.microsoft.com/en-us/library/cc716729(v=vs.110).aspx
// and https://msdn.microsoft.com/en-us/library/yy6y35y8%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
switch (dbType)
{
case DbType.AnsiString:
sqlDbType = SqlDbType.VarChar;
break;
case DbType.Binary:
sqlDbType = SqlDbType.VarBinary;
break;
case DbType.Byte:
sqlDbType = SqlDbType.TinyInt;
break;
case DbType.Boolean:
sqlDbType = SqlDbType.Bit;
break;
case DbType.Currency:
sqlDbType = SqlDbType.Money;
break;
case DbType.Date:
sqlDbType = SqlDbType.Date;
break;
case DbType.DateTime:
sqlDbType = SqlDbType.DateTime;
break;
case DbType.Decimal:
sqlDbType = SqlDbType.Decimal;
break;
case DbType.Double:
sqlDbType = SqlDbType.Float;
break;
case DbType.Guid:
sqlDbType = SqlDbType.UniqueIdentifier;
break;
case DbType.Int16:
sqlDbType = SqlDbType.SmallInt;
break;
case DbType.Int32:
sqlDbType = SqlDbType.Int;
break;
case DbType.Int64:
sqlDbType = SqlDbType.BigInt;
break;
case DbType.Object:
sqlDbType = SqlDbType.Variant;
break;
case DbType.SByte:
throw new NotSupportedException("Inferring a SqlDbType from SByte is not supported.");
case DbType.Single:
sqlDbType = SqlDbType.Real;
break;
case DbType.String:
sqlDbType = SqlDbType.NVarChar;
break;
case DbType.Time:
sqlDbType = SqlDbType.Time;
break;
case DbType.UInt16:
throw new NotSupportedException("Inferring a SqlDbType from UInt16 is not supported.");
case DbType.UInt32:
throw new NotSupportedException("Inferring a SqlDbType from UInt32 is not supported.");
case DbType.UInt64:
throw new NotSupportedException("Inferring a SqlDbType from UInt64 is not supported.");
case DbType.VarNumeric:
throw new NotSupportedException("Inferring a VarNumeric from UInt64 is not supported.");
case DbType.AnsiStringFixedLength:
sqlDbType = SqlDbType.Char;
break;
case DbType.StringFixedLength:
sqlDbType = SqlDbType.NChar;
break;
case DbType.Xml:
sqlDbType = SqlDbType.Xml;
break;
case DbType.DateTime2:
sqlDbType = SqlDbType.DateTime2;
break;
case DbType.DateTimeOffset:
sqlDbType = SqlDbType.DateTimeOffset;
break;
default:
throw new ArgumentOutOfRangeException();
}
return sqlDbType;
}
}
}