我正在使用Insight micro ORM对sql server 2008 R2数据库进行批量插入。当我执行批量插入时,我得到此异常。我不知道为什么会发生这种情况。我确保属性名称和sql服务器表列名称是正确的类型和名称
这是C#代码
Public static void DoBulkInsert(string permissionName)
{
using (IToolTransaction tran = Connection.OpenWithTransactionAs<IToolTransaction>())
{
List<AuditRemovePermisison> audList = new List<AuditRemovePermisison>();
list<int> userIds = getUserIds();
foreach(int userId in userIds)
{
audList.Add(new AuditRemovePermisison
{
ToolId = null,
UserId = userId,
Name = permissionName,
CreatedDate = DateTime.Now
});
}
tran.UsersDeactivateByPermissionName
tran.BulkCopy("RJ.AuditRemovePermission", audList, configure: (InsightBulkCopy bulk) =>
{
bulk.BatchSize = 5000;
},transaction:tran);
tran.Commit();
}
}
和POCO是
public class AuditRemovePermisison
{
public int? ToolId { get; set; }
public int UserId { get; set; }
public string Name { get; set; }
public DateTime CreatedDate { get; set; }
}
[Sql(Schema =“RJ”)]
公共接口IToolTransaction:IDbConnection,IDbTransaction
{
void UsersDeactivateByPermissionName(string PermissionName);
}
Unable to cast object of type 'IToolTransaction1c270692-c6ed-4c04-a8ba-e06109c3c3fd' to type 'Glimpse.Ado.AlternateType.GlimpseDbConnection'.
System.InvalidCastException was caught
HResult=-2147467262
Message=Unable to cast object of type 'IToolTransaction526ca86c-f1e4-4552-80a6-798a2a36d69e' to type 'Glimpse.Ado.AlternateType.GlimpseDbConnection'.
Source=Insight.Database.Providers.Glimpse
StackTrace:
at Insight.Database.Providers.Glimpse.GlimpseInsightDbProvider.GetInnerConnection(IDbConnection connection) in c:\projects.net\Insight\Insight.Database\Insight.Database.Providers.Glimpse\GlimpseInsightDbProvider.cs:line 58
at Insight.Database.Providers.WrappedInsightDbProvider.GetSupportedBulkCopyOptions(IDbConnection connection) in c:\projects.net\Insight\Insight.Database\Insight.Database\Providers\WrappedInsightDbProvider.cs:line 82
at Insight.Database.Providers.DbConnectionWrapperInsightDbProvider.GetSupportedBulkCopyOptions(IDbConnection connection) in c:\projects.net\Insight\Insight.Database\Insight.Database\Providers\DbConnectionWrapperInsightDbProvider.cs:line 41
at Insight.Database.DBConnectionExtensions.BulkCopy(IDbConnection connection, String tableName, IDataReader source, Action`1 configure, Boolean closeConnection, InsightBulkCopyOptions options, IDbTransaction transaction) in c:\projects.net\Insight\Insight.Database\Insight.Database\Extensions\DBConnectionExtensions.cs:line 1380
at Insight.Database.DBConnectionExtensions.BulkCopy[T](IDbConnection connection, String tableName, IEnumerable`1 list, Action`1 configure, Boolean closeConnection, InsightBulkCopyOptions options, IDbTransaction transaction) in c:\projects.net\Insight\Insight.Database\Insight.Database\Extensions\DBConnectionExtensions.cs:line 1339
答案 0 :(得分:0)
在Glimpse包装器和自动生成的界面中,似乎存在双重包装连接的错误。
我已经打开了一个github问题来跟踪这个问题:
https://github.com/jonwagner/Insight.Database/issues/158
与此同时,如果您关闭该场景的一瞥分析,它应该可以工作。我认为它无论如何都不能描述批量拷贝。