使用SQLBulkCopy插入数据后检索标识列

时间:2018-06-15 18:13:58

标签: c# sql .net sql-server

我有一个模特:

(x ==  1)

我使用的是一个EnumerableDataReader,它是IDataReader的一个实现,它似乎工作得很好,除了它没有填充INSERT发生后的身份PROPERTY:A.NameID。这是我的完整代码:

public class A {
       public int NameID {get; set; }  //this represents the identity column in the database
       public string Name { get; set; }
       public string Value { get; set; }
}

此时我希望所有对象的“NameID”都填充当前在该行数据库中的标识列的值。

我做错了什么?

1 个答案:

答案 0 :(得分:2)

void LuaGameObject::Register( lua_State * l ) { luaL_Reg sRegs[] = { { "__index", &LuaGameObject::LuaCallFunction }, { NULL, NULL } }; luaL_newmetatable( l, "luaL_EmpireManager" ); // Register the C functions into the metatable we just created. luaL_setfuncs( l, sRegs, 0 ); lua_pushvalue( l, -1 ); // Set the "__index" field of the metatable to point to itself // This pops the stack lua_setfield( l, -1, "__index" ); // Now we use setglobal to officially expose the luaL_EmpireManager metatable // to Lua. And we use the name "EmpireManager". lua_setglobal( l, "EmpireManager" ); } 仅处理数据复制,而不是高级数据库层。因此,它不负责撤回ID,如果想要的话,实际上不能这样做。

大多数情况下使用的模式是使用SqlBulkCopy插入临时临时表,然后使用SqlBulkCopy将这些行放入主表。

这样您就可以撤回插入的ID并更新模型。