是否可以在samme命令中使用dapper插入值列表和混合值?假设所有属性都与SQL参数匹配,并且:
private class MyObject { public int A { get; set; } public string B { get; set; } } private class YourObject { public int C { get; set; } } private List<MyObject> myObjectList; private List<YourObject> yourObjectList;
此作品:
string query = "INSERT INTO <table1> VALUES (@A, @B);"; connection.Execute(query, myObjectList);
这也有效:
string query = "INSERT INTO <table2> VALUES (@C)"; connection.Execute(query, yourObjectList);
但是我想拥有类似的东西:
string query = "INSERT INTO <table1> VALUES (@A, @B); INSERT INTO <table2> VALUES (@C)";
connection.Execute(query, myObjectList, yourObjectList );
是否可以在samme命令中使用dapper插入值列表和混合值?假定所有属性都与SQL参数匹配,并且:私有类MyObject {public int A {get; ...
You can use storedprocedure to do that.
in DB create procedure like that;
<pre> <i> create procedure sp_dowork
declare @A int,
declare @B int,
declare @C int
as
INSERT INTO <table1> VALUES (@A, @B);
INSERT INTO <table2> VALUES (@C);
end
</pre>
then call procedure from your code like this.
<pre>
string q = "sp_dowork";
connection.Execute(q, myObjectList, yourObjectList)
</pre>
This should work.