Search code examples
linqpad

How to add Linqpad Extension with existing code


I am interested in exporting a SQL SELECT statement to a list of INSERT statements. I found a block of code here that is described as

LINQPad Extensions to generate Class and Insert Statements from SQL

However, I'm not sure how to begin using this in Linqpad. I thought I would just need to copy and paste the code into the "My Extensions" area in Linqpad but that doesn't seem to be working.

Any ideas?


Solution

  • Create a query using your database connection. Set your query mode to Program.

    Append the code after the "Define other methods" comment. Add a line to Main to generate the code and output it:

    CSharpClassFromSqlGeneratorExtensions.DumpInsert(this.Connection, "SELECT * from Accounts").Dump();
    

    or

    CSharpClassFromSqlGeneratorExtensions.DumpClass(this.Connection, "SELECT * from [User]").Dump();
    

    Copy the output into another query.

    I don't find the output very useful when I look at it, however.