Dapper Query<T> vs OrmLite's Query<T> ?

973 views
Skip to first unread message

LyphTEC

unread,
Aug 1, 2012, 12:08:45 AM8/1/12
to servic...@googlegroups.com
Hi,

I just updated to the latest version of OrmLite and noticed that Dapper has now moved to a different namespace and also Query<T> in OrmLite is now hanging directly IDbConnection (from IDbCommand).

There's a few places where I'm using Dapper's version of Query<T> like so:

result = dbConn.Query<string>("select [Email] from [Contacts]");

but now this is broken because it's trying to use OrmLite's version of Query<T> and it doesn't support string as the type because of the where T : new() 

Is there any way I can use IDbConnection extensions from Dapper and OrmLite within the same file and force it to use Dapper's Query() instead?


Thanks.

Demis Bellot

unread,
Aug 1, 2012, 12:16:07 AM8/1/12
to servic...@googlegroups.com
I can think of a couple of options:

1. Both Dapper + OrmLite are extension methods off IDbConnection so just import the one you use most in your C# .cs file and us the fully qualified static method for the other.
2. Since Dapper is just a single source include file, rename Dapper's Query.

On a side-note, Dappers:

result = dbConn.Query<string>("select [Email] from [Contacts]");

can be done like this in OrmLite

result = db.GetScalar<string>("select [Email] from [Contacts]");

LyphTEC

unread,
Aug 1, 2012, 12:26:39 AM8/1/12
to servic...@googlegroups.com
Thanks Demis.

Looks like the fully qualified static method is the way to go for me as the file mainly uses OrmLite and I only use Dapper when I need to return a List<string>.  I actually did not know that you can call the static extension method directly :)

Also, OrmLite's GetScalar<string> is not the same as I need the result to be an IEnumerable<string>

Demis Bellot

unread,
Aug 1, 2012, 12:46:14 AM8/1/12
to servic...@googlegroups.com
Oh, in that case you want :)

List<string> results = db.GetFirstColumn<string>(" select [Email] from [Contacts] ")

Maybe I should provide a better alias? What would be ideal GetList?

LyphTEC

unread,
Aug 1, 2012, 1:49:44 AM8/1/12
to servic...@googlegroups.com
Nice.  Did not know about GetFirstColumn ... yeah, GetList is a probably a bit more discoverable for me.

Thanks again.
Reply all
Reply to author
Forward
0 new messages