Why not just write a simple extension method:
public static int ExecuteFile(this NpgsqlCommand cmd, string filename)
{
string strText = System.IO.File.ReadAllText(filename, System.Text.Encoding.UTF8);
cmd.CommandText = strText;
return cmd.ExecuteNonQuery();
}
Or maybe you'd want to use a custom encoding, like System.Text.Encoding.Default, or something else, then use
public static int ExecuteFile(this NpgsqlCommand cmd, string filename, System.Text.Encoding enc)
{
string strText = System.IO.File.ReadAllText(filename, enc);
cmd.CommandText = strText;
return cmd.ExecuteNonQuery();
}
if you declare it in a static class in namespace Npgsql, then you don't even need an additional include.