Anupam- / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Linq provider for building the SQL #76

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I know it sort of steps away from the core performance orientated design of 
Dapper but I'm currently writing (and have a 60% complete) implementation of a 
Linq provider that works with Dapper.

e.g. cn.Query<Table>().Where( m => m.ak == 3 ).OrderBy( m => m.name );

This generates the SQL:
   SELECT t.[pk], t.[ak], t.[name], ... FROM [table] AS t WHERE t.[ak] = @p0 ORDER BY t.[name]
were ... represents the rest of the properties on the POCO and parameterises
   @p0 = 3
using DynamicParameters

Personally I'm working to SQL server syntax but it should be possible to write 
additional SQL syntax providers.

I anticipate this living alongside the Dapper.Contrib stuff and never becoming 
part of core Dapper.

The goals are:
    1. Support as much of the Linq syntax as possible
    2. thereby allowing code using Dapper to be testable/mockable without the need to interpret SQL

Currently I've made a few mods to the core Dapper which may/may not be accepted
    1. Use the System.ComponentModel.DataAnnotations within the POCOs to do column aliasing / PK finding / table aliasing / schema specification
    2. Becuase I prefer it I'm doing a Connection.Open() if the State was closed within SetupCommand

At present I've got the following working after spending yesterday coding:
    * simple where clauses
    * .HasValue where clauses
    * String.IsNullOrEmpty where clauses
    * sorting
    * take
    * distinct

I'm wondering if people were interested in me pushing this out to the general 
community allowing the code to be reviewed and contributions to be made.

What do people think?

cheers, 

g

Original issue reported on code.google.com by gary.h...@datadeliverynetwork.com on 2 Jan 2012 at 1:07

GoogleCodeExporter commented 9 years ago
I am totally fine with this, clearly this is not in dapper core, but would be 
happy to add another assembly with the LINQ implementation. 

https://github.com/nberardi had a similar effort in the past which did not 
quite get there. 

Original comment by sam.saff...@gmail.com on 22 Jan 2012 at 11:37

GoogleCodeExporter commented 9 years ago
Do you have this posted anywhere? I'd like to take a shot at helping.

Original comment by kjwar...@gmail.com on 26 Jan 2012 at 2:36

GoogleCodeExporter commented 9 years ago
Wow there are a fair few similarities to https://github.com/nberardi - but I 
seem to have a lot more code (probably a bad thing!).

At the moment the code is in a private SVN but I'll get it up to github over 
the next few days.

cheers, g

Original comment by gary.h...@datadeliverynetwork.com on 26 Jan 2012 at 9:14

GoogleCodeExporter commented 9 years ago
I was trying to do the same thing.
have you released your code?
I will look to https://github.com/nberardi

Original comment by dmorganb...@gmail.com on 8 Apr 2012 at 6:17

GoogleCodeExporter commented 9 years ago
Yep I put an early version up on github prior to the github hack so it needs 
reactivating. It's moved on a bit since then and in my own SVN rather than 
publicly available - I'm manic with a deadline this week but will get something 
back up and in place by mid-April

Original comment by gary.h...@codequest.co.uk on 9 Apr 2012 at 1:08

GoogleCodeExporter commented 9 years ago
Apologies if the code doesn't work - but this is where it is hosted... 
https://github.com/garyhuntddn/Dapper.Contrib.Linq.SqlServer

Original comment by gary.h...@codequest.co.uk on 9 Apr 2012 at 1:11