I'm trying to use TVP in dapper to insert several rows at once like this:
con.Execute(@"
INSERT INTO Author (
FirstName,
LastName,
ParentAuthor
)
SELECT
FirstName,
LastName,
ParentAuthor
FROM @TVP
"
, new[]
{
new Author { FirstName = "Roger", LastName = "Smith", ParentAuthor = 1},
new Author { FirstName = "Stan", LastName = "Smith"},
new Author { FirstName = "Haley", LastName = "Smith"},
new Author { FirstName = "Francine", LastName = "Ling"}
} // .AsTableValuedParameter() => not working
);
But is there a convenient way to convert a collection of object into a TableValuedParameter?