Home

Awesome

[!IMPORTANT] as of 2024-03-08 I'm not going to maintain this project anymore. I've moved on to SogePoco


Statically Typed Poco Queries

What is this?

It is a library providing ability to query "Poco family of ORMish things" using statically typed queries. Strictly speaking StaTypPocoQueries.Core is a translator of Linq Expressions into sql text query and its bound parameters. StaTypPocoQueries.AsyncPoco provides extensions to AsyncPoco AsyncPoco.Database class so that queries become available 'natively'. It is possible to use StaTypPocoQueries.Core to provide extensions to other Poco libraries. Use StaTypPocoQueries.PetaPoco to use it with PetaPoco. Original idea for the library: Tytusse (https://github.com/tytusse)

Given one has following entity defined:

[TableName("SomeEntity")]
[PrimaryKey("id")]
[ExplicitColumns] 
class SomeEntity {
    [Column] public int Id { get; set; }
    [Column] public string SomeColumn { get; set; }
}

one can write

db.FetchAsync<SomeEntity>(x => x.SomeColumn == "foo"); //db is of type AsyncPoco.Database

and call will be translated to

db.FetchAsync<SomeEntity>("where [SomeColumn] = @0", new []{"foo"}) 

Full Example

using AsyncPoco;
using StaTypPocoQueries.AsyncPoco;

[TableName("SomeEntity")]
[PrimaryKey("id")]
[ExplicitColumns] 
class SomeEntity {
    [Column] public int Id { get; set; }
    [Column] public string SomeColumn { get; set; }
    [Column] public int anInt { get; set; }
    [Column] public int? nullableInt { get; set; }
}

class YourDataAccessLayer {
	async Task<List<SomeEntity>> Something(Database db) { 
		return await db.FetchAsync<SomeEntity>(x => x.SomeColumn == "foo");
	}
}

How to install it?

Install it from nuget using Visual Studio's dialogs or from command line

Install-Package StaTypPocoQueries.Core
Install-Package StaTypPocoQueries.AsyncPoco

... or compile it from sources.

Is it stable?

I think so. There are plenty of tests for both the translator and for AsyncPoco wrapper using Sqlite and containerized Sql Server.

Features (which constructs are supported?)

NOTE: for brevity all examples below assume quoting of special names using Sql Server dialect: [something] is used to quote something