I have a SQL Server table into which rows are inserted using:
var sql = @"
DECLARE @InsertedRows AS TABLE (Id BIGINT);
INSERT INTO Person ([Name], [Age]) OUTPUT Inserted.Id INTO @InsertedRows
VALUES (@Name, @Age);
SELECT Id FROM @InsertedRows;";
Person person = ...;
var id = connection.Query<long>(sql, person).First();
This all works well however if I try to insert multiple items and return all the inserted ids using:
IEnumerable<Person> people = ...;
var ids = connection.Query<long>(sql, people);
I get an error:
System.InvalidOperationException : An enumerable sequence of parameters (arrays, lists, etc) is not allowed in this context
at Dapper.SqlMapper.GetCacheInfo(Identity identity, Object exampleParameters, Boolean addToCache)
at Dapper.SqlMapper.d__23`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
How would one return multiple inserted ids in Dapper?