Questions tagged [petapoco]

PetaPoco is a tiny and fast micro-ORM for .NET and Mono.

PetaPoco is a tiny and fast single-file or library referenced micro-ORM for .NET and Mono. It prides itself on being an easy to use and no fuss. Support for all the common databases engines are included (SQL Server, SQL Server CE, MS Access, SQLite, MySQL, MariaDB, PostgreSQL, and Oracle databases).

Single file

PetaPoco is available as a single file nuget package, with or without T4 templates to generate POCOs from an existing database schema. In the single file form PetaPoco has zero dependencies.

Speed

PetaPoco benchmarks done by the author can be found here. (Note that there have been several performance improvements made in the code since these benchmarks.)

Frans Bouma's benchmarks can be found here


See the PetaPoco website for a full list of features.

429 questions
4
votes
1 answer

Is this bad or wrong design/implementation of Unit of Work and repository pattern (with transaction) using petapoco

I'm new to this great micro-orm tool (petapoco) and I wonder how to implements UoW and repository pattern using petapoco in web project. I've been read some articles but have no good ideas how to design/implements. Could some one provide some…
ffmm
  • 95
  • 1
  • 7
4
votes
3 answers

Using PetaPoco's Shared Connection with StructureMap

This is my current implementation of StructureMap in Global.asax: var container = (IContainer)IOCContainer.Initialize(); DependencyResolver.SetResolver(new StructureMapDependencyResolver(container)); Below is the code that is refered to…
Jon
  • 38,814
  • 81
  • 233
  • 382
4
votes
2 answers

How can integrate MVCMiniProfiler with PetaPoco without changing the sources

I'm trying to get MVCMiniProfiler to work with PetaPoco I'm trying to set the connection in the creation of the PetaPoco DB, but run into problems (connectionClosed) public class DbHelper { static Database _CurrentDb = null; public static…
smallmouse
  • 55
  • 6
4
votes
4 answers

Why does PetaPoco return from a db.Insert a ID field of 7 as a decimal

When doing a Insert the variable id is returned as an object. However in my database it is an int and in my POCO it is an int however when the method call to ExecuteScalar to return @@IDENTITY is called it returns the number 7 as an object but the…
Jon
  • 38,814
  • 81
  • 233
  • 382
4
votes
3 answers

Best option for dynamic queries?

I'm working on porting an old application to from WebForms to MVC, and part of that process is tearing out the existing data layer, moving the logic from stored procedures to code. As I have initially only worked with basic C# SQL functions…
4
votes
1 answer

Does PetaPoco's Query(string query, parameters) method protect from SQL injection?

In PetaPoco's home page there is a mention that PetaPoco's SQL Builder (Sql object) protects from SQL injection. But does Query(string query, parameters) method protect from SQL injection? SQL Builder is safe: var id = 123; var a =…
Lassi Autio
  • 1,147
  • 1
  • 13
  • 35
4
votes
2 answers

Mapping relationships using PetaPoco paging

I am using PetaPoco v5.1.228.0 and I am trying to fetch a list of people along with the category they belong to, using paging (30 items per page). This is my code: IEnumerable people; var sql = new Sql("SELECT * FROM Person p INNER JOIN…
AndreFeijo
  • 10,044
  • 7
  • 34
  • 64
4
votes
3 answers

Is there a way for me to access a C# class attribute?

Is there a way for me to access a C# class attribute? For instance, if I have the following class: ... [TableName("my_table_name")] public class MyClass { ... } Can I do something like: MyClass.Attribute.TableName => my_table_name Thanks!
ovatsug25
  • 7,786
  • 7
  • 34
  • 48
4
votes
1 answer

How to retrieve xml column in PetaPoco

I was using nvarchar data type in sql (msql-server) to describe Description. But I would like to change the column to an xml data type instead. In my c# datalayer I'm using petapoco to get the data, which is using Ado.Net DataReader. so poco…
tatigo
  • 2,174
  • 1
  • 26
  • 32
4
votes
1 answer

PetaPoco - How to turn off auto increment?

I ran into this error when trying to do an insert: Cannot insert the value NULL into column 'Id' It turns out PetaPoco by default assumes the Id column is auto increment, so even if you provide a value it will attempt to insert null instead. I…
Sgraffite
  • 1,898
  • 3
  • 22
  • 29
4
votes
1 answer

NPoco: Why is my Delete() call, throwing a NullReferenceException?

I'm trying to use NPoco's Delete() method to delete a row from the database. However it just throws a NullReferenceException. I have found a workaround, but I'm wondering if anyone knows why the built in delete function to delete by ID doesn't seem…
NickG
  • 9,315
  • 16
  • 75
  • 115
4
votes
1 answer

How can I use @ in PetaPoco queries

I am trying to use @@ROWCOUNT for an execute query in PetaPoco. Problem is, it consider @@ROWCOUNT like "@ROWCOUNT" parameter because of the @. Must declare the scalar variable "@ROWCOUNT". Here is the execute query code this.Execute(@" …
snaplemouton
  • 1,459
  • 14
  • 28
4
votes
3 answers

How to select and update selected rows in a single sql query?

I have a table named Car Table car ( id int NOT NULL, plate int NOT NULL, sent_to_server bit NOT NULL ); I want to select all Cars which are not sent to server yet SELECT * FROM car WHERE sent_to_server = 0; Then I should update my…
amin
  • 3,672
  • 5
  • 33
  • 61
4
votes
2 answers

How do I used Count(*) with DAL2?

I want to get counts for various groupings of data in some of my tables and am not sure if it is possible using DAL2. I want perform queries such as: SELECT DISTINCT productType, COUNT(*) FROM Products GROUP BY productType The information I come…
RacerNerd
  • 1,579
  • 1
  • 13
  • 31
4
votes
1 answer

PetaPoco ExecuteScalar with nullable Guid

I'm scratching my head trying to work out why petapoco's "Exists()" returns a false where it should return true. I use something like this to test: A simple petapoco model: [TableName("WorkLog")] [PrimaryKey("Id")] public class WorkLog :…
Mackan
  • 6,200
  • 2
  • 25
  • 45