2

I have an SQL script file (that is, a file with a .sql extension) and I want to execute it using PetaPoco in C#. Is that possible?

CodeArtist
  • 5,534
  • 8
  • 40
  • 65

2 Answers2

2

You can read the file and then execute the contents:

string sqlstmt = System.IO.File.ReadAllText(@"C:\Users\Public\something.sql");
db.Execute(sqlstmt);
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206
-1

Answer is no. Which you would know if you tried it. PetaPoco is an ORM - it maps relational tables to objects. Running a random SQL Script does not involve mapping tables to objects. So, your question is like asking if you can use a hammer to drive to the store.

Jasmine
  • 4,003
  • 2
  • 29
  • 39
  • Actually my friend i found that PetaPoco has a Execute function in the source code. I will try to extend Petapoco's Database class.. – CodeArtist May 08 '14 at 01:18
  • Yeah, but why use a hammer to drive to the store, when you can use a car? "Execute" is provided as an add-on, same as in the Entity Framework - but it's not the method you want to use to run random SQL Scripts. Do it the easy way! – Jasmine May 08 '14 at 17:57