简体   繁体   English

SqlBulkCopy 是否支持 MsSql 2017 中的 Graphtables?

[英]Does SqlBulkCopy support Graphtables in MsSql 2017?

I am trying out the new graphdatabase support that was added to Microsoft SQL Server 2017 I wanted to use SqlBulkCopy to insert a couple thousand nodes into a node table.我正在尝试添加到 Microsoft SQL Server 2017的新图形数据库支持我想使用 SqlBulkCopy 将几千个节点插入到节点表中。 However I always the error: Column '$node_id_DB218B0EAE294E37804103CF4E82BCD2' does not allow DBNull.Value.但是我总是错误: Column '$node_id_DB218B0EAE294E37804103CF4E82BCD2' does not allow DBNull.Value.

My tables are create likes this我的桌子是这样创建的

CREATE TABLE [Product] (
[id] bigint,
[name] nvarchar(max),
[partsNum] bigint,
[price] float) AS NODE;

CREATE TABLE [DependsOn] (
[weight] float,
[id] bigint) AS EDGE;`

I prepare my a datatable with all attributes and call SqlBulkCopy like this:我准备了一个包含所有属性的数据表,并像这样调用 SqlBulkCopy:

using (var bulkCopy = new SqlBulkCopy(Connection, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers, null)
{
    DestinationTableName = "Product"
})
{
    bulkCopy.WriteToServer(_dataTable);
}

Now I am wondering if I am doing something wrong or if this is just not supported yet.现在我想知道我是否做错了什么,或者这是否还不受支持。

SqlBulkCopy has no special handling for DataTable ; SqlBulkCopyDataTable没有特殊处理; it will map the columns to copy from source to destination by ordinal position, just as it does for the other overloads that take other sources.它将按顺序位置映射要从源复制到目标的列,就像它为采用其他源的其他重载所做的那样。 So setting up an identity mapping by name isn't optional:因此,按名称设置身份映射不是可选的:

foreach (DataColumn c in dataTable.Columns) {
    sqlBulkCopy.ColumnMappings.Add(c.ColumnName, c.ColumnName);
}

With graph and node tables the problem is a little more noticeable than usual because the internal columns supporting the structures (which you normally don't use explicitly) appear at the start of the column list, so that almost guarantees failure.对于图形和节点表,问题比平常更明显,因为支持结构的内部列(您通常不会明确使用)出现在列列表的开头,因此几乎可以保证失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SqlBulkCopy是否参与环境事务? - Does SqlBulkCopy Enlist in Ambient Transaction? SqlBulkCopy会自动启动事务吗? - Does SqlBulkCopy automatically start a transaction? 点网核心–如何解决:MSSQL 2017超时错误(.Net 4.7.1不会发生) - Dot net Core – How to fix: TimeOut-Error to MSSQL 2017 (which does not happen with .Net 4.7.1) SQLBulkCopy在失败时上传任何数据吗? - Does SQLBulkCopy Upload any data upon failure? SqlBulkCopy - 给定的ColumnName与源或目标中的任何列都不匹配 - SqlBulkCopy - The given ColumnName does not match up with any column in the source or destination SqlBulkCopy.WriteToServerAsync 不遵守 `await` 关键字。 为什么? - SqlBulkCopy.WriteToServerAsync does not respect the `await` keyword. Why? C# MySQL 库是否等效于 SQL SqlBulkCopy class? - Does the C# MySQL library have an equivalent to the SQL SqlBulkCopy class? 在Visual Studio 2017中创建安装项目(带有MSSQL Server数据库) - Create Setup Project in Visual Studio 2017 (with MSSQL Server Database) 在 Linux 上运行应用程序时连接到 MSSQL Server 2017 超时 - Timeout connecting to MSSQL Server 2017 when application running on Linux 无法添加 Docker 支持 Visual Studio 2017 - Cant add Docker Support Visual Studio 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM