Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • marcelh 171 posts 471 karma points
    Nov 26, 2015 @ 13:10
    marcelh
    1

    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:

    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.

  • Max 80 posts 437 karma points
    Feb 24, 2017 @ 15:08
    Max
    1

    Bump... or can someone pass a link with some examples?

  • Carl S 7 posts 87 karma points
    May 26, 2017 @ 06:00
    Carl S
    0

    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

    public class DatabaseService {
        private static readonly Database Database =
            ApplicationContext.Current.DatabaseContext.Database;
    
        private readonly ISqlSyntaxProvider _sqlSyntaxProvider;
    
        public DataService(ISqlSyntaxProvider sqlSyntaxProvider) {
            _sqlSyntaxProvider = sqlSyntaxProvider;
        }
    
        public DatabaseModel FetchSomeData() {
             return Database.Fetch<DatabaseModel>(new Sql().Select("*").From<DatabaseModel>(_sqlSyntaxProvider))
                    .FirstOrDefault();
        }
    }
    

    Or

    private static readonly ISqlSyntaxProvider SqlSyntaxProvider =
                    ApplicationContext.Current.DatabaseContext.SqlSyntax;
    
    Database.Fetch<DatabaseModel>(new Sql().Select("*").From<DatabaseModel>(SqlSyntaxProvider))
                    .FirstOrDefault();
    

    Hope this helps.

  • Max 80 posts 437 karma points
    Jun 01, 2017 @ 12:54
    Max
    0

    Thanks, I'll go back and implement this.

  • ssougnez 93 posts 319 karma points c-trib
    Jul 12, 2018 @ 20:30
    ssougnez
    0

    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 🙏

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    Jul 13, 2018 @ 07:37
    Nik
    1

    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

  • ssougnez 93 posts 319 karma points c-trib
    Jul 13, 2018 @ 07:38
    ssougnez
    0

    Mmmmh, that's what I had in mind while posting but I wanted a confirmation hehe.

    Thanks, it makes sense then :-D

Please Sign in or register to post replies

Write your reply to:

Draft