{"action":"opened","issue":{"url":"https://api.github.com/repos/ServiceStack/Issues/issues/501","repository_url":"https://api.github.com/repos/ServiceStack/Issues","labels_url":"https://api.github.com/repos/ServiceStack/Issues/issues/501/labels{/name}","comments_url":"https://api.github.com/repos/ServiceStack/Issues/issues/501/comments","events_url":"https://api.github.com/repos/ServiceStack/Issues/issues/501/events","html_url":"https://github.com/ServiceStack/Issues/issues/501","id":189529341,"number":501,"title":"OrmLite not respecting unicode settings for input parameters","user":{"login":"bryancrosby","id":1314391,"avatar_url":"https://avatars.githubusercontent.com/u/1314391?v=3","gravatar_id":"","url":"https://api.github.com/users/bryancrosby","html_url":"https://github.com/bryancrosby","followers_url":"https://api.github.com/users/bryancrosby/followers","following_url":"https://api.github.com/users/bryancrosby/following{/other_user}","gists_url":"https://api.github.com/users/bryancrosby/gists{/gist_id}","starred_url":"https://api.github.com/users/bryancrosby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bryancrosby/subscriptions","organizations_url":"https://api.github.com/users/bryancrosby/orgs","repos_url":"https://api.github.com/users/bryancrosby/repos","events_url":"https://api.github.com/users/bryancrosby/events{/privacy}","received_events_url":"https://api.github.com/users/bryancrosby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-15T22:46:37Z","updated_at":"2016-11-15T22:46:37Z","closed_at":null,"body":"For the given DbParam, the value never gets assigned to SqlDbType.VarChar -- it (rightly so) defaults to NVarChar by the ADO.NET provider, however, this behavior is not always wanted if certain databases are not using Unicode.\r\n\r\nGetStringConverter().UseUnicode does not seem to have an effect (and is also false by default)\r\n\r\nGiven a simple POCO that I got from UpdateTests.cs\r\n\r\n```C#\r\n    public class SimpleType\r\n    {\r\n        [AutoIncrement]\r\n        public int Id { get; set; }\r\n        [Alias(\"name\")]\r\n        public string Name { get; set; }\r\n    }\r\n```\r\nHowever, taking a look at the output on the server, \r\n```sql\r\nexec sp_executesql N'UPDATE \"SimpleType\" SET \"name\"=@name WHERE ((\"Id\" = @0) AND (\"name\" = @1))',N'@0 int,@1 nvarchar(max) ,@name nvarchar(19)',@0=1,@1=N'Somename',@name=N'a new updated value'\r\n```\r\n\r\nThe following converter seems to correct the behavior\r\n```C#\r\n    public class NVarcharToVarcharStringConverter : StringConverter\r\n    {\r\n        public override void InitDbParam(IDbDataParameter p, Type fieldType)\r\n        {\r\n            base.InitDbParam(p, fieldType);\r\n\r\n            var sqlParam = p as SqlParameter;\r\n            if (sqlParam != null)\r\n            {\r\n                if (!UseUnicode)\r\n                {\r\n                    sqlParam.SqlDbType = SqlDbType.VarChar;\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    cf.DialectProvider.RegisterConverter<string>(new NVarcharToVarcharStringConverter());\r\n\r\n```"}}
{"actor":{"display_login":"bryancrosby"}}