I have recently upgraded my solution to Umbraco 7.3.1, and some warnings are generated on compilation for methods in PetaPocoSqlExtenions.
Consider the statement below:
var result = Context.Database.Fetch<LoginHistory>(new Sql().Select("*").From<LoginHistory>().Where<LoginHistory>(f => f.CustomerReference == customer));
This results in 'Umbraco.Core.Persistence.PetaPocoSqlExtensions.From
But when I change the statement above into:
var result = Context.Database.Fetch<LoginHistory>(new Sql().Select("*").From<LoginHistory>(SqlSyntaxContext.SqlSyntaxProvider).Where<LoginHistory>(f => f.CustomerReference == customer));
This results in 'Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxContext' is obsolete: 'This should not be used, the ISqlSyntaxProvider is part of the DatabaseContext or should be injected into your services as a constructor parameter'
I really liked the construction of SQL statements this way. How can I continue using this syntax without relying on these obsolete methods? Googling doesn't give me the updated syntax and looking into the Umbraco codebase, I can't find the updated usages either.
I believe the SqlSyntax parameter tells the method what type of database you use using. Out of the box you could be using full SQL, SQLCE or MySQL. The syntax for MySQL is slightly different in some situations, and I believe there might be the odd nuance between SQL ans SQLCE.
(I'm not 100% on this but I believe it is the case)
Obsolete PetaPocoSqlExtensions
I have recently upgraded my solution to Umbraco 7.3.1, and some warnings are generated on compilation for methods in PetaPocoSqlExtenions.
Consider the statement below:
This results in 'Umbraco.Core.Persistence.PetaPocoSqlExtensions.From
But when I change the statement above into:
This results in 'Umbraco.Core.Persistence.SqlSyntax.SqlSyntaxContext' is obsolete: 'This should not be used, the ISqlSyntaxProvider is part of the DatabaseContext or should be injected into your services as a constructor parameter'
I really liked the construction of SQL statements this way. How can I continue using this syntax without relying on these obsolete methods? Googling doesn't give me the updated syntax and looking into the Umbraco codebase, I can't find the updated usages either.
Bump... or can someone pass a link with some examples?
Hi
'This should not be used, the ISqlSyntaxProvider is part of the DatabaseContext or should be injected into your services as a constructor parameter'
Inject it into your constructor
Or
Hope this helps.
Thanks, I'll go back and implement this.
Hi,
Sorry to dig this topic up but I was wondering why we need to pass this SqlSyntax parameters, what does it do? What is it used for?
Thanks 🙏
Hi ssougnezc,
I believe the SqlSyntax parameter tells the method what type of database you use using. Out of the box you could be using full SQL, SQLCE or MySQL. The syntax for MySQL is slightly different in some situations, and I believe there might be the odd nuance between SQL ans SQLCE.
(I'm not 100% on this but I believe it is the case)
Thanks,
Nik
Mmmmh, that's what I had in mind while posting but I wanted a confirmation hehe.
Thanks, it makes sense then :-D
is working on a reply...