Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavior between SQL Server 2016 and SQL Server 2008 R2 #606

Closed
labilbe opened this issue Mar 28, 2018 · 6 comments
Closed

Different behavior between SQL Server 2016 and SQL Server 2008 R2 #606

labilbe opened this issue Mar 28, 2018 · 6 comments

Comments

@labilbe
Copy link

labilbe commented Mar 28, 2018

Hi,

Symptoms

My code runs fine on SQL Server 2016 (dev) but throws SqlException with message 'CONCAT' n'est pas une option nom de fonction intégrée reconnue. Syntaxe incorrecte vers 'Clients'. Syntaxe incorrecte vers 'Clients'. in SQL Server 2008 R2.

Explanation

I am using ServiceStack.OrmLite on a database hosted on SQL Server 2016 (dev env) and same code is applied to SQL Server 2008 R2 (prod env).
I know CONCAT function is not supported on SQL Server 2008 R2, and I would like to know if it is possible to force something like SqlServer2008Dialect.Provider, so the generated function will not be using CONCAT.
In consequence I am using something like that var dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["mydatabase"].ConnectionString, SqlServerDialect.Provider).
My version of ServiceStack is 4.5.14.

Thank you.

@mythz
Copy link
Member

mythz commented Mar 28, 2018

Which generated function are you referring to? Please provide a stand-alone code example.

@labilbe
Copy link
Author

labilbe commented Mar 28, 2018

Here is a code fragment of C# code

      var ev = db.From()
                .Join((p, q) => p.Id == q.CustomerId && q.DocumentSendingModeId != DocumentSendingMode.Fax)
                .LeftJoin((p, q) => p.Id == q.ThirdPartyId && q.Prefix == CustomerContact.DefaultPrefix && q.Civility == "Adresse" && q.Name == "adresse facture")
                .Select((p, q, r) => new
                {
                    Id = Sql.As(p.IdNumber, nameof(CustomerEskerExport.Id)),
                    Email = Sql.As(q.DocumentSendingModeId == DocumentSendingMode.Email ? p.AccountingEmail : "", nameof(CustomerEskerExport.Email)),
                    Address = Sql.As(q.DocumentSendingModeId == DocumentSendingMode.SnailMail ? (r.ThirdPartyId ?? "") == "" ? p.Address + "\r\n" + p.PostalCode + " " + p.City + "\r\n" + p.CountryId : r.Address + "\r\n" + r.PostalCode + " " + r.City + "\r\n" + r.CountryId : "", nameof(CustomerEskerExport.Address)),
                    SendingMode = Sql.As(q.DocumentSendingModeId, nameof(CustomerEskerExport.SendingMode))
                });
            var eskerExports = db.Select(ev);

@labilbe
Copy link
Author

labilbe commented Mar 28, 2018

The line Address = Sql.As(q.DocumentSendingModeId == DocumentSendingMode.SnailMail ? (r.ThirdPartyId ?? "") == "" ? p.Address + "\r\n" + p.PostalCode + " " + p.City + "\r\n" + p.CountryId : r.Address + "\r\n" + r.PostalCode + " " + r.City + "\r\n" + r.CountryId : "", nameof(CustomerEskerExport.Address)), is generating SQL code with CONCAT function, even on SQL Server 2008 R2.

@labilbe
Copy link
Author

labilbe commented Mar 28, 2018

@mythz , is is ok for you or you need something shorter?

@mythz
Copy link
Member

mythz commented Mar 28, 2018

I've added support for the new SqlServer2008Dialect.Provider with a custom SqlConcat() in this commit and an x-xplat Sql.Cast(field, Sql.VARCHAR) in this commit.

Note: SQL Server 2008's + operator is more fragile than the CONCAT operator and will require casting non-char columns you want to concatenate.

This change is available from v5.0.3 that's now available on MyGet.

@mythz mythz closed this as completed Mar 28, 2018
@labilbe
Copy link
Author

labilbe commented Mar 29, 2018

Wow! Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants