我在VB应用程序中使用ADO.NET数据集.我有一个带有一个父表和许多子表的类型化数据集.我想在将数据插入父表时生成身份密钥,然后使用相同的密钥(作为Foregin密钥)更新所有子表中的数据.
最后,我想更新数据库(SQL Server08)中的数据集.
好吧,首先可以通过直接在数据库中插入父表,获取Identity列而不是用于Child表来实现上述功能.
但是我想将它作为一个自动操作(就像LINQ to SQL一样,它在datacontext中处理主键和外键.)
我在Dataset中可能会为父表和子表处理Autogenerated列吗?
谢谢,
ABB
与下面提到的其他问题类似,我有两个表格结构:
create table parent (
recno int identity(1,1) primary key not null,
groupCode int,
parentdata varchar(80)
);
create table child (
parentrecno int not null,
childdata varchar(80)
)
Run Code Online (Sandbox Code Playgroud)
我需要在这些表中快速插入几十万个记录 - 这些表包含数百万个与此插入无关的其他记录,并且永远不会安静.由于父/子的性质,它似乎不是一个好的候选人(似乎)SqlBulkCopy.
在C#中使用SqlCommand,INSERT我得到大约400-500条记录/秒插入,这有点太慢了.伪代码:
foreach(Record r in parentRecords)
{
Insert Fields from r into SqlCommand Parameters but not "recno"
Call ExecuteScalar to insert and fetch the inserted identity value (recno)
foreach(ChildRecord cr in parentRecords.Children)
{
Insert Fields from cr into SqlCommand Parameters
Insert the identity value …Run Code Online (Sandbox Code Playgroud)