{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/25638330","id":25638330,"diff_hunk":"@@ -0,0 +1,140 @@\n+﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Reflection;\n+using JetBrains.Annotations;\n+using Microsoft.Data.Entity.Utilities;\n+using Microsoft.Framework.Logging;\n+\n+namespace Microsoft.Data.Entity.SqlServer.Design.Utilities\n+{\n+    public class SqlServerLiteralUtilities\n+    {\n+        public SqlServerLiteralUtilities([NotNull] ILogger logger)\n+        {\n+            Check.NotNull(logger, nameof(logger));\n+\n+            Logger = logger;\n+        }\n+\n+        public virtual ILogger Logger { get; }\n+\n+        /// <summary>\n+        /// Converts a string of the form 'There''s a double single quote in here'\n+        /// (including the outer single quotes) to the string literal\n+        /// \"There's a double single quote in here\" (not including the double quotes).\n+        /// </summary>\n+        /// <param name=\"sqlServerStringLiteral\"> the string to convert </param>\n+        /// <returns> the converted string, or null if it cannot convert </returns>\n+        public virtual string ConvertSqlServerStringLiteral([NotNull] string sqlServerStringLiteral)\n+        {\n+            Check.NotEmpty(sqlServerStringLiteral, nameof(sqlServerStringLiteral));\n+\n+            var sqlServerStringLiteralLength = sqlServerStringLiteral.Length;\n+            if (sqlServerStringLiteralLength < 2)\n+            {\n+                Logger.WriteWarning(Strings.CannotInterpretSqlServerStringLiteral(sqlServerStringLiteral));\n+                return null;\n+            }\n+\n+            if (sqlServerStringLiteral[0] != '\\'' ||\n+                sqlServerStringLiteral[sqlServerStringLiteralLength-1] != '\\'')\n+            {\n+                Logger.WriteWarning(Strings.CannotInterpretSqlServerStringLiteral(sqlServerStringLiteral));\n+                return null;\n+            }\n+\n+            return sqlServerStringLiteral.Substring(1, sqlServerStringLiteralLength - 2)\n+                .Replace(\"''\", \"'\");\n+        }\n+\n+        /// <summary>\n+        /// SQL Server stores the values 0 or 1 in bit columns. Interpret these\n+        /// as false and true respectively.\n+        /// </summary>\n+        /// <param name=\"sqlServerStringLiteral\"> the string to convert </param>\n+        /// <returns>\n+        /// false if the string can be interpreted as 0, true if it can be\n+        /// intrepreted as 1, otherwise null\n+        /// </returns>\n+        public virtual bool? ConvertSqlServerBitLiteral([NotNull] string sqlServerStringLiteral)\n+        {\n+            Check.NotEmpty(sqlServerStringLiteral, nameof(sqlServerStringLiteral));\n+\n+            int result;\n+            if (int.TryParse(sqlServerStringLiteral, out result))\n+            {\n+                if (result == 0)\n+                {\n+                    return false;\n+                }\n+\n+                if (result == 1)\n+                {\n+                    return true;\n+                }\n+            }\n+\n+            return null;\n+        }\n+\n+        public virtual object ConvertSqlServerDefaultValue(\n+            [NotNull] Type propertyType , [NotNull] string sqlServerDefaultValue)\n+        {\n+            Check.NotNull(propertyType, nameof(propertyType));\n+            Check.NotEmpty(sqlServerDefaultValue, nameof(sqlServerDefaultValue));\n+\n+            if (sqlServerDefaultValue.Length < 2)\n+            {\n+                return null;\n+            }\n+\n+            while (sqlServerDefaultValue[0] == '('\n+                && sqlServerDefaultValue[sqlServerDefaultValue.Length - 1] == ')')\n+            {\n+                sqlServerDefaultValue = sqlServerDefaultValue.Substring(1, sqlServerDefaultValue.Length - 2);\n+            }\n+\n+            if (string.IsNullOrEmpty(sqlServerDefaultValue))\n+            {\n+                return null;\n+            }\n+\n+            propertyType = propertyType.IsNullableType()\n+                ? Nullable.GetUnderlyingType(propertyType)\n+                : propertyType;\n+\n+            if (typeof(string) == propertyType)\n+            {\n+                return ConvertSqlServerStringLiteral(sqlServerDefaultValue);\n+            }\n+\n+            if (typeof(bool) == propertyType)\n+            {\n+                return ConvertSqlServerBitLiteral(sqlServerDefaultValue);\n+            }\n+\n+            //TODO: decide what to do about byte[] default values and the values\n+            // newid() and getdate() for Guid and DateTime respectively\n+\n+            var parseMethodInfo =\n+                propertyType\n+                    .GetRuntimeMethod(\"Parse\", new Type[] { typeof(string) });","path":"src/EntityFramework.SqlServer.Design/Utilities/SqlServerLiteralUtilities.cs","position":124,"original_position":124,"commit_id":"df20055f60b639bd74f5301ef7f9bf6e1094f8b5","original_commit_id":"df20055f60b639bd74f5301ef7f9bf6e1094f8b5","user":{"login":"lajones","id":1915927,"avatar_url":"https://avatars.githubusercontent.com/u/1915927?v=3","gravatar_id":"","url":"https://api.github.com/users/lajones","html_url":"https://github.com/lajones","followers_url":"https://api.github.com/users/lajones/followers","following_url":"https://api.github.com/users/lajones/following{/other_user}","gists_url":"https://api.github.com/users/lajones/gists{/gist_id}","starred_url":"https://api.github.com/users/lajones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lajones/subscriptions","organizations_url":"https://api.github.com/users/lajones/orgs","repos_url":"https://api.github.com/users/lajones/repos","events_url":"https://api.github.com/users/lajones/events{/privacy}","received_events_url":"https://api.github.com/users/lajones/received_events","type":"User","site_admin":false},"body":"I had to add a dependency on System.Runtime.Extensions. After that Convert was available everywhere. So have changed to use Convert.ChangeType().","created_at":"2015-03-02T21:05:35Z","updated_at":"2015-03-02T21:05:35Z","html_url":"https://github.com/aspnet/EntityFramework/pull/1710#discussion_r25638330","pull_request_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710","_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/25638330"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/1710#discussion_r25638330"},"pull_request":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710","id":30039055,"html_url":"https://github.com/aspnet/EntityFramework/pull/1710","diff_url":"https://github.com/aspnet/EntityFramework/pull/1710.diff","patch_url":"https://github.com/aspnet/EntityFramework/pull/1710.patch","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1710","number":1710,"state":"open","locked":false,"title":"Adding DefaultValue code generation","user":{"login":"lajones","id":1915927,"avatar_url":"https://avatars.githubusercontent.com/u/1915927?v=3","gravatar_id":"","url":"https://api.github.com/users/lajones","html_url":"https://github.com/lajones","followers_url":"https://api.github.com/users/lajones/followers","following_url":"https://api.github.com/users/lajones/following{/other_user}","gists_url":"https://api.github.com/users/lajones/gists{/gist_id}","starred_url":"https://api.github.com/users/lajones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lajones/subscriptions","organizations_url":"https://api.github.com/users/lajones/orgs","repos_url":"https://api.github.com/users/lajones/repos","events_url":"https://api.github.com/users/lajones/events{/privacy}","received_events_url":"https://api.github.com/users/lajones/received_events","type":"User","site_admin":false},"body":"See Issue #1670.\r\n\r\nThis deals with fixed default values only. There are also expressions which are returned in the metadata - e.g. newid() and getdate() - which I will address separately.","created_at":"2015-02-26T00:11:22Z","updated_at":"2015-03-02T21:05:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab5f57d131538d0d5aea2e15966ce7af6870db06","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710/commits","review_comments_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710/comments","review_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/1710/comments","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/df20055f60b639bd74f5301ef7f9bf6e1094f8b5","head":{"label":"aspnet:lajones150224_RevEngDefaultValues_01","ref":"lajones150224_RevEngDefaultValues_01","sha":"df20055f60b639bd74f5301ef7f9bf6e1094f8b5","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16157746,"name":"EntityFramework","full_name":"aspnet/EntityFramework","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/EntityFramework","description":"Microsoft's recommended data access technology for new applications in .NET.","fork":false,"url":"https://api.github.com/repos/aspnet/EntityFramework","forks_url":"https://api.github.com/repos/aspnet/EntityFramework/forks","keys_url":"https://api.github.com/repos/aspnet/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/EntityFramework/teams","hooks_url":"https://api.github.com/repos/aspnet/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/EntityFramework/events","assignees_url":"https://api.github.com/repos/aspnet/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/EntityFramework/tags","blobs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/aspnet/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/aspnet/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/aspnet/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/aspnet/EntityFramework/subscription","commits_url":"https://api.github.com/repos/aspnet/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/EntityFramework/merges","archive_url":"https://api.github.com/repos/aspnet/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/EntityFramework/downloads","issues_url":"https://api.github.com/repos/aspnet/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/EntityFramework/releases{/id}","created_at":"2014-01-23T00:52:01Z","updated_at":"2015-03-02T20:34:53Z","pushed_at":"2015-03-02T20:41:15Z","git_url":"git://github.com/aspnet/EntityFramework.git","ssh_url":"git@github.com:aspnet/EntityFramework.git","clone_url":"https://github.com/aspnet/EntityFramework.git","svn_url":"https://github.com/aspnet/EntityFramework","homepage":"","size":47246,"stargazers_count":1370,"watchers_count":1370,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":349,"mirror_url":null,"open_issues_count":347,"forks":349,"open_issues":347,"watchers":1370,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"f7bcf1f501ba4c75bf5b4108b9520958e579db12","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16157746,"name":"EntityFramework","full_name":"aspnet/EntityFramework","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/EntityFramework","description":"Microsoft's recommended data access technology for new applications in .NET.","fork":false,"url":"https://api.github.com/repos/aspnet/EntityFramework","forks_url":"https://api.github.com/repos/aspnet/EntityFramework/forks","keys_url":"https://api.github.com/repos/aspnet/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/EntityFramework/teams","hooks_url":"https://api.github.com/repos/aspnet/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/EntityFramework/events","assignees_url":"https://api.github.com/repos/aspnet/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/EntityFramework/tags","blobs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/aspnet/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/aspnet/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/aspnet/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/aspnet/EntityFramework/subscription","commits_url":"https://api.github.com/repos/aspnet/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/EntityFramework/merges","archive_url":"https://api.github.com/repos/aspnet/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/EntityFramework/downloads","issues_url":"https://api.github.com/repos/aspnet/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/EntityFramework/releases{/id}","created_at":"2014-01-23T00:52:01Z","updated_at":"2015-03-02T20:34:53Z","pushed_at":"2015-03-02T20:41:15Z","git_url":"git://github.com/aspnet/EntityFramework.git","ssh_url":"git@github.com:aspnet/EntityFramework.git","clone_url":"https://github.com/aspnet/EntityFramework.git","svn_url":"https://github.com/aspnet/EntityFramework","homepage":"","size":47246,"stargazers_count":1370,"watchers_count":1370,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":349,"mirror_url":null,"open_issues_count":347,"forks":349,"open_issues":347,"watchers":1370,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/1710"},"issue":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/1710"},"comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/1710/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/1710/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/EntityFramework/statuses/df20055f60b639bd74f5301ef7f9bf6e1094f8b5"}}}}