Skip to content

Commit

Permalink
Support TVP parameters with .dacpac stored procedures (#2328)
Browse files Browse the repository at this point in the history
fixes #2322
  • Loading branch information
ErikEJ authored May 13, 2024
1 parent c54bad9 commit 5b3ca80
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 8 deletions.
20 changes: 19 additions & 1 deletion src/Core/NUnitTestCore/Dacpac/DacpacTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using RevEng.Core.Abstractions;

namespace UnitTests
{
Expand Down Expand Up @@ -204,7 +205,7 @@ public void Issue1262_BehaviourWithoutSchemaArgument()
}

[Test]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Test")]
public void Temporal_Support()
{
var factory = new SqlServerDacpacDatabaseModelFactory(null);
Expand All @@ -218,6 +219,23 @@ public void Temporal_Support()
ClassicAssert.NotNull(dbModel.Tables.Single().FindAnnotation(SqlServerAnnotationNames.IsTemporal));
}

[Test]
public void Issue_2322_Tvp_Sproc_Parameters()
{
var factory = new SqlServerDacpacStoredProcedureModelFactory(
new SqlServerDacpacDatabaseModelFactoryOptions{ MergeDacpacs = false });
var options = new ModuleModelFactoryOptions { FullModel = true, Modules = new List<string>() };

// Act
var dbModel = factory.Create(TestPath("TvpParams.dacpac"), options);

// Assert
ClassicAssert.AreEqual(1, dbModel.Routines.Count);
ClassicAssert.AreEqual(2, dbModel.Routines[0].Parameters.Count);
ClassicAssert.AreEqual("[Constant].[NumberIDList]", dbModel.Routines[0].Parameters[0].TypeName);
ClassicAssert.AreEqual("structured", dbModel.Routines[0].Parameters[0].StoreType);
}

private string TestPath(string file)
{
return Path.Combine(TestContext.CurrentContext.TestDirectory, "Dacpac", file);
Expand Down
Binary file added src/Core/NUnitTestCore/Dacpac/TvpParams.dacpac
Binary file not shown.
4 changes: 4 additions & 0 deletions src/Core/NUnitTestCore/NUnitTestCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<None Remove="ChinookContext.txt" />
<None Remove="Dacpac\Issue1262.dacpac" />
<None Remove="Dacpac\Temporal.dacpac" />
<None Remove="Dacpac\TvpParams.dacpac" />
<None Remove="Identity.txt" />
<None Remove="Issue208.dacpac" />
<None Remove="Issue210.dacpac" />
Expand All @@ -37,6 +38,9 @@
<Content Include="Dacpac\Temporal.dacpac">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Dacpac\TvpParams.dacpac">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Dgml\Aw2014Person.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Binary file modified src/GUI/lib/efreveng60.exe.zip
Binary file not shown.
Binary file modified src/GUI/lib/efreveng70.exe.zip
Binary file not shown.
Binary file modified src/GUI/lib/efreveng80.exe.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PackageId>ErikEJ.EntityFrameworkCore.SqlServer.Dacpac</PackageId>
<PackageVersion>7.0.6</PackageVersion>
<PackageVersion>7.0.7</PackageVersion>
<NoWarn>$(NoWarn);EF1001</NoWarn>
<Authors>ErikEJ</Authors>
<Description>Enables reverse engineering an EF Core model from a data-tier application package (DACPAC).</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PackageId>ErikEJ.EntityFrameworkCore.SqlServer.Dacpac</PackageId>
<PackageVersion>8.0.3</PackageVersion>
<PackageVersion>8.0.4</PackageVersion>
<NoWarn>$(NoWarn);EF1001</NoWarn>
<Authors>ErikEJ</Authors>
<Description>Enables reverse engineering an EF Core model from a data-tier application package (DACPAC).</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PackageId>ErikEJ.EntityFrameworkCore.SqlServer.Dacpac</PackageId>
<PackageVersion>6.0.6</PackageVersion>
<PackageVersion>6.0.7</PackageVersion>
<NoWarn>$(NoWarn);EF1001</NoWarn>
<Authors>ErikEJ</Authors>
<Description>Enables reverse engineering an EF Core model from a data-tier application package (DACPAC).</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ private static List<ModuleParameter> GetStoredProcedureParameters(TSqlProcedure
{
var result = new List<ModuleParameter>();

string typeName = null;

foreach (var parameter in proc.Parameters)
{
var storeType = parameter.DataType.First().Name.Parts[0];
Expand All @@ -117,14 +119,18 @@ private static List<ModuleParameter> GetStoredProcedureParameters(TSqlProcedure
storeType = dtReference.Type.First().Name.Parts[0];
}

var udtReference = parameter.DataType.First() as TSqlUserDefinedTypeReference;

#pragma warning disable S2219 // Runtime type checking should be simplified
if (udtReference != null)
if (parameter.DataType.First() is TSqlUserDefinedTypeReference udtReference)
{
storeType = udtReference.Name.Parts[1];
}

if (parameter.DataType.First() is TSqlTableTypeReference tableReference)
{
// parameter is a table type (TVP)
storeType = "structured";
typeName = tableReference.Name.ToString();
}

#pragma warning restore S2219 // Runtime type checking should be simplified

var newParameter = new ModuleParameter()
Expand All @@ -136,6 +142,7 @@ private static List<ModuleParameter> GetStoredProcedureParameters(TSqlProcedure
Scale = parameter.Scale,
StoreType = storeType,
Nullable = true,
TypeName = typeName,
};

result.Add(newParameter);
Expand Down

0 comments on commit 5b3ca80

Please sign in to comment.