U4-8287 - Refactor ISqlSyntaxProvider usage in Sql queries

Created by Stephan 05 Apr 2016, 12:29:04 Updated by Shannon Deminick 12 Apr 2016, 13:13:06

Is required for: U4-5544

At the moment most queries look like:

var sql = new Sql()...Where(SqlSyntax, x => x.Whatever == 3);

I.e. the SqlSyntax needs to be passed around everywhere. With NPoco and some changes, we also need to pass around the IPocoDataFactory that countains the tables & columns definitions, amongst other things.

This is going to complexify these Where(...) methods (and others) with irrelevant parameters. Proposal is to do something along:

var sql = Sql.Builder(database).Where(x => x.Whatever == 3);

I.e. have an UmbracoSql class inheriting from Sql and containing references to the various things that are needed.


Stephan 07 Apr 2016, 13:47:00

part of PR https://github.com/umbraco/Umbraco-CMS/pull/1207 all done

syntax now is: var sql = new Sql().For(sqlContext).Select(...);

where sqlContext is an SqlContext object that contains the SqlSyntax, DatabaseType, and IPocoDataFactory. In the base repository I've created a helper method, so syntax can actually be: var sql = Sql().Select(...);

Makes for much ligther code. Currently discussing with Adam re. how this could be part of NPoco which would be super cool.

Priority: Normal

Type: Task

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 8.0.0

Sprint: Sprint 13

Story Points: