[英]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
; SqlBulkCopy
对DataTable
没有特殊处理; 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.