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?
Asked
Active
Viewed 1,222 times
2

michaelb958--GoFundMonica
- 4,617
- 7
- 31
- 35

CodeArtist
- 5,534
- 8
- 40
- 65
-
2What happened when you tried it? – Jasmine May 07 '14 at 16:41
-
I didn't tried yet because i don't know how. Using traditional c# code i can do it but using PetaPoco i don't know how... – CodeArtist May 07 '14 at 16:43
-
PetaPoco is an Object-Relational-Mapping provider. Is there any Object-Relational-Mapping required to run a SQL Script? – Jasmine May 07 '14 at 21:41
2 Answers
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