diff --git a/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.csproj b/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.csproj index 43eb4d6..4a07ad3 100644 --- a/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.csproj +++ b/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.csproj @@ -15,6 +15,7 @@ + diff --git a/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.sln b/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.sln index 21ce7cc..740f70e 100644 --- a/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.sln +++ b/EntityFrameworkCore/Dgmjr.Primitives.EntityFrameworkCore.sln @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Primitives", "..\src\Dgmjr.Primitives.csproj", "{4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Primitives.EntityFrameworkCore", "Dgmjr.Primitives.EntityFrameworkCore.csproj", "{E7E23589-B331-4475-B0D3-9645F65D9CCC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Primitives.EntityFrameworkCore", "Dgmjr.Primitives.EntityFrameworkCore.csproj", "{5B975267-5DCE-419A-AC37-F9215357106C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -34,18 +34,18 @@ Global {4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}.Production|Any CPU.Build.0 = Local|Any CPU {4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E1F4A52-7F97-43E1-AAA6-2EEEE07326E6}.Release|Any CPU.Build.0 = Release|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Local|Any CPU.ActiveCfg = Local|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Local|Any CPU.Build.0 = Local|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Testing|Any CPU.ActiveCfg = Testing|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Testing|Any CPU.Build.0 = Testing|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Staging|Any CPU.ActiveCfg = Staging|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Staging|Any CPU.Build.0 = Staging|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Production|Any CPU.ActiveCfg = Local|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Production|Any CPU.Build.0 = Local|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E7E23589-B331-4475-B0D3-9645F65D9CCC}.Release|Any CPU.Build.0 = Release|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Local|Any CPU.ActiveCfg = Local|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Local|Any CPU.Build.0 = Local|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Testing|Any CPU.ActiveCfg = Testing|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Testing|Any CPU.Build.0 = Testing|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Staging|Any CPU.ActiveCfg = Staging|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Staging|Any CPU.Build.0 = Staging|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Production|Any CPU.ActiveCfg = Local|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Production|Any CPU.Build.0 = Local|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B975267-5DCE-419A-AC37-F9215357106C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/EntityFrameworkCore/EmailAddressEfCoreExtensions.cs b/EntityFrameworkCore/EmailAddressEfCoreExtensions.cs index 3641f8c..f6e1bc4 100644 --- a/EntityFrameworkCore/EmailAddressEfCoreExtensions.cs +++ b/EntityFrameworkCore/EmailAddressEfCoreExtensions.cs @@ -78,11 +78,13 @@ public static MigrationBuilder HasIsValidEmailAddressFunction( string functionName ) { - migrationBuilder.Sql( - typeof(Constants).Assembly - .ReadAssemblyResourceAllText(IsValidEmailAddress + _sql) - .Replace("{schema}", schema) - .Replace("{functionName}", functionName) + migrationBuilder.Operations.Add( + new CreateFunctionOperation( + schema, + functionName, + "@value nvarchar(MAX)", + typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsValidEmailAddress + _sql) + ) ); return migrationBuilder; } @@ -102,7 +104,7 @@ public static MigrationBuilder RollBackIsValidEmailAddressFunction( string functionName ) { - migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]"); + migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName)); return migrationBuilder; } diff --git a/EntityFrameworkCore/ObjectIdEfCoreExtensions.cs b/EntityFrameworkCore/ObjectIdEfCoreExtensions.cs index 71b02ae..d2d5c2b 100644 --- a/EntityFrameworkCore/ObjectIdEfCoreExtensions.cs +++ b/EntityFrameworkCore/ObjectIdEfCoreExtensions.cs @@ -49,17 +49,20 @@ public static MigrationBuilder HasIsValidObjectIdFunction( string functionName ) { - migrationBuilder.Sql( - typeof(Constants).Assembly - .GetManifestResourceStream(ufn_ + "IsValidObjectId.sql") - .ReadToEnd() + migrationBuilder.Operations.Add( + new CreateFunctionOperation( + schema, + functionName, + "@value nvarchar(MAX)", + typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsValidObjectId + _sql) + ) ); return migrationBuilder; } public static MigrationBuilder RollBackIsValidObjectIdFunction( this MigrationBuilder migrationBuilder - ) => migrationBuilder.RollBackIsValidObjectIdFunction(ufn_ + "IsValidObjectId"); + ) => migrationBuilder.RollBackIsValidObjectIdFunction(IsValidObjectId); public static MigrationBuilder RollBackIsValidObjectIdFunction( this MigrationBuilder migrationBuilder, @@ -72,15 +75,15 @@ public static MigrationBuilder RollBackIsValidObjectIdFunction( string functionName ) { - migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}];"); + migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName)); return migrationBuilder; } #if NET7_0_OR_GREATER - public static Microsoft.EntityFrameworkCore.Metadata.Builders.TableBuilder HasObjectIdCheckConstraint( - this Microsoft.EntityFrameworkCore.Metadata.Builders.TableBuilder tableBuilder, + public static TableBuilder HasObjectIdCheckConstraint( + this TableBuilder tableBuilder, string columnName, - string functionName = "IsValidObjectId", + string functionName = IsValidObjectId, string schema = DboSchema.ShortName ) { diff --git a/EntityFrameworkCore/PhoneNumberEfCoreExtensions.cs b/EntityFrameworkCore/PhoneNumberEfCoreExtensions.cs index b547e58..4a8c762 100644 --- a/EntityFrameworkCore/PhoneNumberEfCoreExtensions.cs +++ b/EntityFrameworkCore/PhoneNumberEfCoreExtensions.cs @@ -53,11 +53,13 @@ public static MigrationBuilder HasIsValidPhoneNumberFunction( string functionName ) { - migrationBuilder.Sql( - typeof(Constants).Assembly - .ReadAssemblyResourceAllText(IsValidPhoneNumber + _sql) - .Replace("{schema}", schema) - .Replace("{functionName}", functionName) + migrationBuilder.Operations.Add( + new CreateFunctionOperation( + schema, + functionName, + "@value nvarchar(MAX)", + typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsValidPhoneNumber + _sql) + ) ); return migrationBuilder; } diff --git a/EntityFrameworkCore/Resources/ufn_IsUri.sql b/EntityFrameworkCore/Resources/ufn_IsUri.sql index 1f84ee8..86e95aa 100644 --- a/EntityFrameworkCore/Resources/ufn_IsUri.sql +++ b/EntityFrameworkCore/Resources/ufn_IsUri.sql @@ -1,4 +1,4 @@ RETURN CASE - WHEN @uri LIKE '%:%' THEN 1 + WHEN @value LIKE '%:%' THEN 1 ELSE 0 END diff --git a/EntityFrameworkCore/Resources/ufn_IsUrl.sql b/EntityFrameworkCore/Resources/ufn_IsUrl.sql index b17ebb2..6321723 100644 --- a/EntityFrameworkCore/Resources/ufn_IsUrl.sql +++ b/EntityFrameworkCore/Resources/ufn_IsUrl.sql @@ -1,5 +1,5 @@ RETURN - CASE WHEN @url LIKE '%://%' + CASE WHEN @value LIKE '%://%' -- OR @url LIKE 'http://%' -- OR @url LIKE 'ftp://%' -- OR @url LIKE 'tg://%' diff --git a/EntityFrameworkCore/Resources/ufn_IsUrn.sql b/EntityFrameworkCore/Resources/ufn_IsUrn.sql index 17320c5..453ba19 100644 --- a/EntityFrameworkCore/Resources/ufn_IsUrn.sql +++ b/EntityFrameworkCore/Resources/ufn_IsUrn.sql @@ -1 +1 @@ -RETURN CASE WHEN @urn LIKE 'urn:%' THEN 1 ELSE 0 END +RETURN CASE WHEN @value LIKE 'urn:%' THEN 1 ELSE 0 END diff --git a/EntityFrameworkCore/Resources/ufn_IsValidEmailAddress.sql b/EntityFrameworkCore/Resources/ufn_IsValidEmailAddress.sql index bd1d83d..2b5b225 100644 --- a/EntityFrameworkCore/Resources/ufn_IsValidEmailAddress.sql +++ b/EntityFrameworkCore/Resources/ufn_IsValidEmailAddress.sql @@ -1,7 +1,7 @@ DECLARE @bitEmailVal as Bit -DECLARE @EmailText nvarchar(MAX) = @EMAIL +DECLARE @EmailText nvarchar(MAX) = @value -SET @EmailText=ltrim(rtrim(isnull(@EMAIL,''))) +SET @EmailText=ltrim(rtrim(isnull(@value,''))) SET @bitEmailVal = case when @EmailText = '' then 0 when @EmailText like '% %' then 0 diff --git a/EntityFrameworkCore/Resources/ufn_IsValidObjectId.sql b/EntityFrameworkCore/Resources/ufn_IsValidObjectId.sql index 5822784..1e86b6a 100644 --- a/EntityFrameworkCore/Resources/ufn_IsValidObjectId.sql +++ b/EntityFrameworkCore/Resources/ufn_IsValidObjectId.sql @@ -1,5 +1,5 @@ RETURN CASE - WHEN @objectId LIKE '[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' + WHEN @value LIKE '[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' THEN 1 ELSE 0 END diff --git a/EntityFrameworkCore/Resources/ufn_IsValidPhoneNumber.sql b/EntityFrameworkCore/Resources/ufn_IsValidPhoneNumber.sql index 94e00ab..74468d6 100644 --- a/EntityFrameworkCore/Resources/ufn_IsValidPhoneNumber.sql +++ b/EntityFrameworkCore/Resources/ufn_IsValidPhoneNumber.sql @@ -1,12 +1,12 @@ RETURN CASE - WHEN @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' - OR @phoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + WHEN @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' + OR @value LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' THEN 1 ELSE 0 END diff --git a/EntityFrameworkCore/UriEfCoreExtensions.cs b/EntityFrameworkCore/UriEfCoreExtensions.cs index 9e31ea2..87049cc 100644 --- a/EntityFrameworkCore/UriEfCoreExtensions.cs +++ b/EntityFrameworkCore/UriEfCoreExtensions.cs @@ -1,3 +1,5 @@ +using Dgmjr.EntityFrameworkCore.Migrations; + namespace Dgmjr.Primitives.EntityFrameworkCore; public static class UriEfCoreExtensions @@ -33,11 +35,13 @@ public static MigrationBuilder HasIsValidUriFunction( string functionName ) { - migrationBuilder.Sql( - typeof(Constants).Assembly - .ReadAssemblyResourceAllText(IsUri + _sql) - .Replace("{schema}", schema) - .Replace("{functionName}", functionName) + migrationBuilder.Operations.Add( + new CreateFunctionOperation( + schema, + functionName, + "@value nvarchar(MAX)", + typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsUri + _sql) + ) ); return migrationBuilder; } @@ -57,7 +61,7 @@ public static MigrationBuilder RollBackIsValidUriFunction( string functionName ) { - migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]"); + migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName)); return migrationBuilder; } diff --git a/EntityFrameworkCore/UrlEfCoreExtensions.cs b/EntityFrameworkCore/UrlEfCoreExtensions.cs index 5e0fafe..b3e59c7 100644 --- a/EntityFrameworkCore/UrlEfCoreExtensions.cs +++ b/EntityFrameworkCore/UrlEfCoreExtensions.cs @@ -32,11 +32,13 @@ public static MigrationBuilder HasIsValidUrlFunction( string functionName ) { - migrationBuilder.Sql( - typeof(Constants).Assembly - .ReadAssemblyResourceAllText(IsUrl + _sql) - .Replace("{schema}", schema) - .Replace("{functionName}", functionName) + migrationBuilder.Operations.Add( + new CreateFunctionOperation( + schema, + functionName, + "@value nvarchar(MAX)", + typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsUrl + _sql) + ) ); return migrationBuilder; } @@ -56,7 +58,7 @@ public static MigrationBuilder RollBackIsValidUrlFunction( string functionName ) { - migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]"); + migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName)); return migrationBuilder; } diff --git a/EntityFrameworkCore/UrnEfCoreExtensions.cs b/EntityFrameworkCore/UrnEfCoreExtensions.cs index 02cd4d3..a825b58 100644 --- a/EntityFrameworkCore/UrnEfCoreExtensions.cs +++ b/EntityFrameworkCore/UrnEfCoreExtensions.cs @@ -46,11 +46,13 @@ public static MigrationBuilder HasIsValidUrnFunction( string functionName ) { - migrationBuilder.Sql( - typeof(Constants).Assembly - .ReadAssemblyResourceAllText(IsUrn + _sql) - .Replace("{schema}", schema) - .Replace("{functionName}", functionName) + migrationBuilder.Operations.Add( + new CreateFunctionOperation( + schema, + functionName, + "@value nvarchar(MAX)", + typeof(Constants).Assembly.ReadAssemblyResourceAllText(IsUrn + _sql) + ) ); return migrationBuilder; } @@ -70,7 +72,7 @@ public static MigrationBuilder RollBackIsValidUrnFunction( string functionName ) { - migrationBuilder.Sql($"DROP FUNCTION IF EXISTS [{schema}].[{functionName}]"); + migrationBuilder.Operations.Add(new DropFunctionOperation(schema, functionName)); return migrationBuilder; }