Skip to content

How to write Linq2Db version of TVP Query #4281

Closed Answered by viceroypenguin
DDSGooch asked this question in Q&A
Discussion options

You must be logged in to vote

If you ahve 40k records to do a join with, I'd recommend you create a temporary table. Bulk loading the data into the table will most likely be faster than creating an insanely long SQL query and forcing the server to parse it. You can do that as such:

private record ContactName(string Name);

[Test]
public async Task BulkLoadJoin()
{
  DataConnection.TurnTraceSwitchOn();
  DataConnection.WriteTraceLine = (message, s1, s2) => NUnit.Serilog.Log.ForCurrentTest().Information("{SQL}", message);
  using var dbConnection = DbConnectionFactory();

  var contactTable = dbConnection.Value.CreateTable<Contact>();

  contactTable.Insert(() => new Contact
  {
    Name = "John",
    City = "London",
  })

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@viceroypenguin
Comment options

Answer selected by DDSGooch
@DDSGooch
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants