diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index c95e021..b8acd8d 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -23,6 +23,7 @@ jobs:
dotnet-version: |
6.0.x
8.0.x
+ 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
diff --git a/EFCore.VisualBasic.Templates/EFCore.VisualBasic.Templates.vbproj b/EFCore.VisualBasic.Templates/EFCore.VisualBasic.Templates.vbproj
index 32d1550..e0f5586 100644
--- a/EFCore.VisualBasic.Templates/EFCore.VisualBasic.Templates.vbproj
+++ b/EFCore.VisualBasic.Templates/EFCore.VisualBasic.Templates.vbproj
@@ -16,7 +16,7 @@
content
Unlicense
True
- 8.0.0
+ 8.0.0-alpha
© 2024 Brice Lambson, et al. All rights reserved.
https://github.com/efcore/EFCore.VisualBasic
https://github.com/efcore/EFCore.VisualBasic.git
diff --git a/EFCore.VisualBasic/Design/Internal/VisualBasicHelper.vb b/EFCore.VisualBasic/Design/Internal/VisualBasicHelper.vb
index 730fb9f..7c9673c 100644
--- a/EFCore.VisualBasic/Design/Internal/VisualBasicHelper.vb
+++ b/EFCore.VisualBasic/Design/Internal/VisualBasicHelper.vb
@@ -1181,7 +1181,7 @@ Namespace Design.Internal
For Each methodCall In frag.MethodCalls
builder.
Append(frag.Parameter).
- AppendLine(Fragment(methodCall, indent))
+ AppendLine(Fragment(methodCall, indent + 1))
Next
End Using
diff --git a/EFCore.VisualBasic/EFCore.VisualBasic.vbproj b/EFCore.VisualBasic/EFCore.VisualBasic.vbproj
index 45df4ab..cadc818 100644
--- a/EFCore.VisualBasic/EFCore.VisualBasic.vbproj
+++ b/EFCore.VisualBasic/EFCore.VisualBasic.vbproj
@@ -12,7 +12,7 @@
true
key.snk
true
- 8.0.0
+ 9.0.0-alpha
true
On
latest
@@ -47,18 +47,18 @@
-
-
-
+
+
+
all
-
+
all
-
+
all
-
+
all
diff --git a/EFCore.VisualBasic/Migrations/Design/VisualBasicMigrationsGenerator.vb b/EFCore.VisualBasic/Migrations/Design/VisualBasicMigrationsGenerator.vb
index 24964e4..a9f5bbd 100644
--- a/EFCore.VisualBasic/Migrations/Design/VisualBasicMigrationsGenerator.vb
+++ b/EFCore.VisualBasic/Migrations/Design/VisualBasicMigrationsGenerator.vb
@@ -31,9 +31,11 @@ Namespace Migrations.Design
VBCode = NotNull(vbHelper, NameOf(vbHelper))
VisualBasicMigrationOperationGenerator = New VisualBasicMigrationOperationGenerator(vbHelper)
+#Disable Warning BC40008 ' Type or member is obsolete
VisualBasicSnapshotGenerator = New VisualBasicSnapshotGenerator(dependencies.AnnotationCodeGenerator,
dependencies.RelationalTypeMappingSource,
vbHelper)
+#Enable Warning BC40008 ' Type or member is obsolete
End Sub
'''
@@ -188,8 +190,8 @@ Namespace Migrations.Design
Dim namespaces = New List(Of String) From {
"Microsoft.EntityFrameworkCore",
"Microsoft.EntityFrameworkCore.Infrastructure",
- "Microsoft.EntityFrameworkCore.Metadata",
"Microsoft.EntityFrameworkCore.Migrations",
+ "Microsoft.EntityFrameworkCore.Storage.ValueConversion",
"Microsoft.VisualBasic"
}
@@ -270,8 +272,7 @@ Namespace Migrations.Design
Dim namespaces = New List(Of String) From {
"Microsoft.EntityFrameworkCore",
"Microsoft.EntityFrameworkCore.Infrastructure",
- "Microsoft.EntityFrameworkCore.Metadata",
- "Microsoft.EntityFrameworkCore.Migrations",
+ "Microsoft.EntityFrameworkCore.Storage.ValueConversion",
"Microsoft.VisualBasic"
}
diff --git a/EFCore.VisualBasic/Migrations/Design/VisualBasicSnapshotGenerator.vb b/EFCore.VisualBasic/Migrations/Design/VisualBasicSnapshotGenerator.vb
index 70d105f..0389309 100644
--- a/EFCore.VisualBasic/Migrations/Design/VisualBasicSnapshotGenerator.vb
+++ b/EFCore.VisualBasic/Migrations/Design/VisualBasicSnapshotGenerator.vb
@@ -153,16 +153,15 @@ Namespace Migrations.Design
Dim ownership = entityType.FindOwnership()
Dim ownerNavigation = ownership?.PrincipalToDependent.Name
- Dim GetOwnedName = Function(type As ITypeBase, simpleName As String, ownershipNavigation As String) As String
- Return type.Name & "." & ownershipNavigation & "#" & simpleName
- End Function
-
Dim entityTypeName = entityType.Name
If ownerNavigation IsNot Nothing AndAlso
- entityType.HasSharedClrType AndAlso
- entityTypeName = GetOwnedName(ownership.PrincipalEntityType, entityType.ClrType.ShortDisplayName(), ownerNavigation) Then
+ entityType.HasSharedClrType Then
- entityTypeName = entityType.ClrType.DisplayName()
+ If entityTypeName = ownership.PrincipalEntityType.GetOwnedName(entityType.ClrType.ShortDisplayName(), ownerNavigation) Then
+ entityTypeName = entityType.ClrType.DisplayName()
+ ElseIf entityTypeName = ownership.PrincipalEntityType.GetOwnedName(entityType.ShortName(), ownerNavigation) Then
+ entityTypeName = entityType.ShortName()
+ End If
End If
Dim entityTypeBuilderName = GenerateNestedBuilderName(builderName)
@@ -185,7 +184,7 @@ Namespace Migrations.Design
stringBuilder.
Append("Sub(").
Append(entityTypeBuilderName).
- AppendLine(")"c)
+ Append(")"c)
Using stringBuilder.Indent()
GenerateBaseType(entityTypeBuilderName, entityType.BaseType, stringBuilder)
@@ -299,7 +298,7 @@ Namespace Migrations.Design
AppendLine(","c)
Using stringBuilder.Indent()
- stringBuilder.AppendLine("Sub(b)")
+ stringBuilder.Append("Sub(b)")
Using stringBuilder.Indent()
GenerateRelationships("b", entityType, stringBuilder)
@@ -470,13 +469,7 @@ Namespace Migrations.Design
NotNull(properties, NameOf(properties))
NotNull(stringBuilder, NameOf(stringBuilder))
- Dim first = True
For Each [property] In properties
- If first Then
- first = False
- Else
- stringBuilder.AppendLine()
- End If
GenerateProperty(entityTypeBuilderName, [property], stringBuilder)
Next
End Sub
@@ -495,11 +488,13 @@ Namespace Migrations.Design
NotNull([property], NameOf([property]))
NotNull(stringBuilder, NameOf(stringBuilder))
- Dim clrType = If(FindValueConverter([property])?.ProviderClrType.MakeNullable([property].IsNullable), [property].ClrType)
+ Dim clrType = If(FindValueConverter([property])?.ProviderClrType, [property].ClrType).MakeNullable([property].IsNullable)
- Dim propertyBuilderName = $"{entityTypeBuilderName}.Property(Of {VBCode.Reference(clrType)})({VBCode.Literal([property].Name)})"
+ Dim propertyCall = If([property].IsPrimitiveCollection, "PrimitiveCollection", "Property")
+ Dim propertyBuilderName = $"{entityTypeBuilderName}.{propertyCall}(Of {VBCode.Reference(clrType)})({VBCode.Literal([property].Name)})"
stringBuilder.
+ AppendLine().
Append(propertyBuilderName)
' Note that GenerateAnnotations below does the corresponding decrement
@@ -596,7 +591,7 @@ Namespace Migrations.Design
End Sub
Private Shared Function FindValueConverter([property] As IProperty) As ValueConverter
- Return If([property].GetValueConverter(), [property].GetTypeMapping().Converter)
+ Return [property].GetTypeMapping().Converter
End Function
'''
@@ -640,8 +635,7 @@ Namespace Migrations.Design
If complexProperty.IsNullable <> complexProperty.ClrType.IsNullableType() Then
stringBuilder.
Append(complexTypeBuilderName).
- AppendLine(".IsRequired()").
- AppendLine()
+ AppendLine(".IsRequired()")
End If
GenerateProperties(complexTypeBuilderName, ComplexType.GetDeclaredProperties(), stringBuilder)
@@ -946,62 +940,65 @@ Namespace Migrations.Design
If(discriminatorMappingCompleteAnnotation?.Value,
discriminatorValueAnnotation?.Value)) IsNot Nothing Then
- stringBuilder.
+ Dim discriminatorProperty = entityType.FindDiscriminatorProperty()
+ If discriminatorProperty IsNot Nothing Then
+
+ stringBuilder.
AppendLine().
Append(entityTypeBuilderName).
Append("."c).
Append("HasDiscriminator")
- Dim discriminatorProperty = entityType.FindDiscriminatorProperty()
- If discriminatorPropertyAnnotation?.Value IsNot Nothing AndAlso
- discriminatorProperty IsNot Nothing Then
+ If discriminatorProperty.DeclaringType Is entityType AndAlso
+ discriminatorProperty.Name <> "Discriminator" Then
- Dim propertyClrType = If(FindValueConverter(discriminatorProperty)?.
+ Dim propertyClrType = If(FindValueConverter(discriminatorProperty)?.
ProviderClrType.
MakeNullable(discriminatorProperty.IsNullable),
discriminatorProperty.ClrType)
- stringBuilder.
+ stringBuilder.
Append("(Of ").
Append(VBCode.Reference(propertyClrType)).
Append(")(").
Append(VBCode.Literal(discriminatorProperty.Name)).
Append(")"c)
- Else
- stringBuilder.
+ Else
+ stringBuilder.
Append("()")
- End If
+ End If
- If discriminatorMappingCompleteAnnotation?.Value IsNot Nothing Then
- Dim value = CBool(discriminatorMappingCompleteAnnotation.Value)
+ If discriminatorMappingCompleteAnnotation?.Value IsNot Nothing Then
+ Dim value = CBool(discriminatorMappingCompleteAnnotation.Value)
- stringBuilder.
+ stringBuilder.
Append("."c).
Append("IsComplete").
Append("("c).
Append(VBCode.Literal(value)).
Append(")"c)
- End If
+ End If
- If discriminatorValueAnnotation?.Value IsNot Nothing Then
- Dim value = discriminatorValueAnnotation.Value
+ If discriminatorValueAnnotation?.Value IsNot Nothing Then
+ Dim value = discriminatorValueAnnotation.Value
- If discriminatorProperty IsNot Nothing Then
- Dim valueConverter = FindValueConverter(discriminatorProperty)
- If valueConverter IsNot Nothing Then
- value = valueConverter.ConvertToProvider(value)
+ If discriminatorProperty IsNot Nothing Then
+ Dim valueConverter = FindValueConverter(discriminatorProperty)
+ If valueConverter IsNot Nothing Then
+ value = valueConverter.ConvertToProvider(value)
+ End If
End If
- End If
- stringBuilder.
+ stringBuilder.
Append("."c).
Append("HasValue").
Append("("c).
Append(VBCode.UnknownLiteral(value)).
Append(")"c)
- End If
+ End If
- stringBuilder.AppendLine()
+ stringBuilder.AppendLine()
+ End If
End If
GenerateAnnotations(entityTypeBuilderName, entityType, stringBuilder, annotations, inChainedCall:=False)
@@ -1098,19 +1095,18 @@ Namespace Migrations.Design
End If
If requiresTableBuilder Then
-
If explicitName Then
stringBuilder.AppendLine(","c)
End If
Using stringBuilder.Indent()
- stringBuilder.AppendLine("Sub(t)")
+ stringBuilder.Append("Sub(t)")
Using stringBuilder.Indent()
If isExcludedFromMigrations Then
stringBuilder.
- AppendLine("t.ExcludeFromMigrations()").
- AppendLine()
+ AppendLine().
+ AppendLine("t.ExcludeFromMigrations()")
End If
If comment IsNot Nothing Then
@@ -1153,7 +1149,7 @@ Namespace Migrations.Design
AppendLine(","c)
Using stringBuilder.Indent()
- stringBuilder.AppendLine("Sub(t)")
+ stringBuilder.Append("Sub(t)")
Using stringBuilder.Indent()
GenerateTriggers("t", entityType, Table.Name, Table.Schema, stringBuilder)
@@ -1224,7 +1220,7 @@ Namespace Migrations.Design
stringBuilder.AppendLine(","c)
Using stringBuilder.Indent()
- stringBuilder.AppendLine("Sub(v)")
+ stringBuilder.Append("Sub(v)")
Using stringBuilder.Indent()
GeneratePropertyOverrides("v", entityType, View.Value, stringBuilder)
@@ -1253,7 +1249,7 @@ Namespace Migrations.Design
AppendLine(","c)
Using stringBuilder.Indent()
- stringBuilder.AppendLine("Sub(v)")
+ stringBuilder.Append("Sub(v)")
Using stringBuilder.Indent()
GeneratePropertyOverrides("v", entityType, fragment.StoreObject, stringBuilder)
@@ -1349,18 +1345,22 @@ Namespace Migrations.Design
FilterIgnoredAnnotations(checkConstraint.GetAnnotations()).
ToDictionary(Function(a) a.Name, Function(a) a)
- If hasNonDefaultName Then
- stringBuilder.
- AppendLine("."c).
- Append("HasName(").
- Append(VBCode.Literal(checkConstraint.Name)).
- Append(")"c)
- End If
+ Using stringBuilder.Indent()
+ If hasNonDefaultName Then
+ stringBuilder.
+ AppendLine("."c).
+ Append("HasName(").
+ Append(VBCode.Literal(checkConstraint.Name)).
+ Append(")"c)
+ End If
- If annotations.Count > 0 Then
- GenerateAnnotations("t", checkConstraint, stringBuilder, annotations, inChainedCall:=True)
- stringBuilder.IncrementIndent()
- End If
+ If annotations.Count > 0 Then
+ GenerateAnnotations("t", checkConstraint, stringBuilder, annotations, inChainedCall:=True)
+ stringBuilder.IncrementIndent()
+ Else
+ stringBuilder.AppendLine()
+ End If
+ End Using
End Sub
'''
@@ -1425,8 +1425,8 @@ Namespace Migrations.Design
Dim nameAnnotation As IAnnotation = Nothing
If annotations.TryGetAndRemove(RelationalAnnotationNames.Name, nameAnnotation) Then
stringBuilder.
- AppendLine().
- Append(".HasDatabaseName(").
+ AppendLine("."c).
+ Append("HasDatabaseName(").
Append(VBCode.Literal(CStr(nameAnnotation.Value))).
Append(")"c)
End If
@@ -1518,13 +1518,8 @@ Namespace Migrations.Design
NotNull(foreignKeys, NameOf(foreignKeys))
NotNull(stringBuilder, NameOf(stringBuilder))
- Dim isFirst = True
For Each foreignKey In foreignKeys
- If isFirst Then
- isFirst = False
- Else
- stringBuilder.AppendLine()
- End If
+ stringBuilder.AppendLine()
GenerateForeignKey(entityTypeBuilderName, foreignKey, stringBuilder)
Next
@@ -1692,7 +1687,7 @@ Namespace Migrations.Design
AppendLine(","c)
Using stringBuilder.Indent()
- stringBuilder.AppendLine("Sub(b)")
+ stringBuilder.Append("Sub(b)")
Using stringBuilder.Indent()
GenerateNavigations("b", entityType.GetDeclaredNavigations().
@@ -1718,13 +1713,8 @@ Namespace Migrations.Design
NotNull(navigations, NameOf(navigations))
NotNull(stringBuilder, NameOf(stringBuilder))
- Dim isFirst = True
For Each navigation In navigations
- If isFirst Then
- isFirst = False
- Else
- stringBuilder.AppendLine()
- End If
+ stringBuilder.AppendLine()
GenerateNavigation(entityTypeBuilderName, navigation, stringBuilder)
Next
@@ -1846,7 +1836,7 @@ Namespace Migrations.Design
stringBuilder.AppendLine()
End Using
- stringBuilder.Append(" }")
+ stringBuilder.Append("}"c)
Next
End Using
diff --git a/EFCore.VisualBasic/Scaffolding/Internal/VisualBasicModelGenerator.vb b/EFCore.VisualBasic/Scaffolding/Internal/VisualBasicModelGenerator.vb
index b509f46..8999c0e 100644
--- a/EFCore.VisualBasic/Scaffolding/Internal/VisualBasicModelGenerator.vb
+++ b/EFCore.VisualBasic/Scaffolding/Internal/VisualBasicModelGenerator.vb
@@ -75,12 +75,12 @@ Namespace Scaffolding.Internal
'output DbContext .vb file
Dim dbContextFileName = options.ContextName & host.Extension
Dim resultingFiles As New ScaffoldedModel With {
- .ContextFile = New ScaffoldedFile With {
- .Path = If(options.ContextDir IsNot Nothing,
+ .ContextFile = New ScaffoldedFile(
+ path:=If(options.ContextDir IsNot Nothing,
Path.Combine(options.ContextDir, dbContextFileName),
dbContextFileName),
- .Code = generatedCode
- }
+ code:=generatedCode
+ )
}
For Each entityType In model.GetEntityTypes()
@@ -104,13 +104,13 @@ Namespace Scaffolding.Internal
generatedCode = ProcessTemplate(entityTypeTemplate)
If String.IsNullOrWhiteSpace(generatedCode) Then Continue For
- ' output EntityType poco.vb file
+ ' output EntityType poco .vb file
Dim entityTypeFileName = entityType.Name & host.Extension
resultingFiles.AdditionalFiles.Add(
- New ScaffoldedFile With {
- .Path = entityTypeFileName,
- .Code = generatedCode
- })
+ New ScaffoldedFile(
+ path:=entityTypeFileName,
+ code:=generatedCode
+ ))
Next
Return resultingFiles
diff --git a/NuGet.Config b/NuGet.Config
index e59e698..0271598 100644
--- a/NuGet.Config
+++ b/NuGet.Config
@@ -3,6 +3,7 @@
+
diff --git a/Sandbox/Sandbox.vbproj b/Sandbox/Sandbox.vbproj
index 564191e..b4aeae3 100644
--- a/Sandbox/Sandbox.vbproj
+++ b/Sandbox/Sandbox.vbproj
@@ -8,10 +8,10 @@
-
-
-
-
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Test/EFCore.Design.Tests.Shared/EFCore.Design.Tests.Shared.csproj b/Test/EFCore.Design.Tests.Shared/EFCore.Design.Tests.Shared.csproj
index d8d6eb8..2f68ba0 100644
--- a/Test/EFCore.Design.Tests.Shared/EFCore.Design.Tests.Shared.csproj
+++ b/Test/EFCore.Design.Tests.Shared/EFCore.Design.Tests.Shared.csproj
@@ -1,13 +1,13 @@
- net8.0
+ net9.0
True
-
-
+
+
diff --git a/Test/EFCore.Design.Tests.Shared/EntityFrameworkCore.VisualBasic.Test/Scaffolding/Internal/MyJsonGuidReaderWriter.cs b/Test/EFCore.Design.Tests.Shared/EntityFrameworkCore.VisualBasic.Test/Scaffolding/Internal/MyJsonGuidReaderWriter.cs
deleted file mode 100644
index 7be160d..0000000
--- a/Test/EFCore.Design.Tests.Shared/EntityFrameworkCore.VisualBasic.Test/Scaffolding/Internal/MyJsonGuidReaderWriter.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Microsoft.EntityFrameworkCore.Storage.Json;
-using System;
-using System.Text.Json;
-
-namespace EntityFrameworkCore.VisualBasic.Scaffolding.Internal
-{
- public sealed class MyJsonGuidReaderWriter : JsonValueReaderWriter
- {
- public override Guid FromJsonTyped(ref Utf8JsonReaderManager manager, object existingObject = null)
- => manager.CurrentReader.GetGuid();
-
- public override void ToJsonTyped(Utf8JsonWriter writer, Guid value)
- => writer.WriteStringValue(value);
- }
-}
diff --git a/Test/EFCore.VisualBasic.Test/Design/Internal/VisualBasicHelperTests.vb b/Test/EFCore.VisualBasic.Test/Design/Internal/VisualBasicHelperTests.vb
index eacd28d..ec2a921 100644
--- a/Test/EFCore.VisualBasic.Test/Design/Internal/VisualBasicHelperTests.vb
+++ b/Test/EFCore.VisualBasic.Test/Design/Internal/VisualBasicHelperTests.vb
@@ -813,7 +813,7 @@ $"builder.
method3,
New MethodCallCodeFragment(
_testFuncMethodInfo,
- New NestedClosureCodeFragment("tb", {
+ New NestedClosureCodeFragment("tbb", {
method4,
method5
}))
@@ -827,10 +827,10 @@ $"builder.
TestFunc(Sub(tb) tb.TestFunc(2)).
TestFunc(Sub(tb)
tb.TestFunc(3)
- tb.TestFunc(Sub(tb)
- tb.TestFunc(4)
- tb.TestFunc(5)
- End Sub)
+ tb.TestFunc(Sub(tbb)
+ tbb.TestFunc(4)
+ tbb.TestFunc(5)
+ End Sub)
End Sub)", result, ignoreLineEndingDifferences:=True)
End Sub
diff --git a/Test/EFCore.VisualBasic.Test/EFCore.VisualBasic.Test.vbproj b/Test/EFCore.VisualBasic.Test/EFCore.VisualBasic.Test.vbproj
index dd74a1f..50a689a 100644
--- a/Test/EFCore.VisualBasic.Test/EFCore.VisualBasic.Test.vbproj
+++ b/Test/EFCore.VisualBasic.Test/EFCore.VisualBasic.Test.vbproj
@@ -1,7 +1,7 @@
- net8.0
+ net9.0
true
false
EntityFrameworkCore.VisualBasic
@@ -25,26 +25,26 @@
-
-
-
+
+
+
all
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationOperationGeneratorTest.vb b/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationOperationGeneratorTest.vb
index 7dde1ef..737ec5f 100644
--- a/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationOperationGeneratorTest.vb
+++ b/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationOperationGeneratorTest.vb
@@ -12,7 +12,6 @@ Imports NetTopologySuite.Geometries
Imports Xunit
Namespace Migrations.Design
-
Public Class VisualBasicMigrationOperationGeneratorTest
Private Shared ReadOnly _nl As String = Environment.NewLine
@@ -2617,7 +2616,7 @@ mb.Sql(""-- close to me"")"
{
.Table = "People",
.Columns = {"Tags"},
- .Values = New Object(,) {{New String() {}}}
+ .Values = New Object(,) {{Array.Empty(Of String)()}}
}
Dim expectedCode =
@@ -2633,7 +2632,7 @@ mb.Sql(""-- close to me"")"
Assert.[Single](o.Columns)
Assert.Equal(1, o.Values.GetLength(0))
Assert.Equal(1, o.Values.GetLength(1))
- Assert.Equal(New String() {}, CType(o.Values(0, 0), String()).AsEnumerable())
+ Assert.Equal(Array.Empty(Of String)(), CType(o.Values(0, 0), String()).AsEnumerable())
End Sub)
End Sub
@@ -2644,7 +2643,7 @@ mb.Sql(""-- close to me"")"
{
.Table = "People",
.Columns = {"First Name", "Last Name", "Geometry"},
- .Values = New Object(,) {{"John", Nothing, New String() {}}}
+ .Values = New Object(,) {{"John", Nothing, Array.Empty(Of String)()}}
}
Dim expectedCode =
@@ -2661,7 +2660,7 @@ mb.Sql(""-- close to me"")"
Assert.Equal(1, o.Values.GetLength(0))
Assert.Equal(3, o.Values.GetLength(1))
Assert.Null(o.Values(0, 1))
- Assert.Equal(New String() {}, CType(o.Values(0, 2), String()).AsEnumerable())
+ Assert.Equal(Array.Empty(Of String)(), CType(o.Values(0, 2), String()).AsEnumerable())
End Sub)
End Sub
@@ -3451,7 +3450,5 @@ mb.Sql(""-- close to me"")"
assertAction(result)
End Sub
-
End Class
-
End Namespace
diff --git a/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTest.ModelSnapshot.vb b/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTest.ModelSnapshot.vb
new file mode 100644
index 0000000..c2dddd0
--- /dev/null
+++ b/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTest.ModelSnapshot.vb
@@ -0,0 +1,8467 @@
+Imports System.ComponentModel.DataAnnotations
+Imports System.ComponentModel.DataAnnotations.Schema
+Imports System.Reflection
+Imports System.Text
+Imports System.Text.RegularExpressions
+Imports EntityFrameworkCore.VisualBasic.Design.Internal
+Imports EntityFrameworkCore.VisualBasic.TestUtilities
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.ChangeTracking
+Imports Microsoft.EntityFrameworkCore.Design
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Metadata.Internal
+Imports Microsoft.EntityFrameworkCore.Migrations
+Imports Microsoft.EntityFrameworkCore.Migrations.Design
+Imports Microsoft.EntityFrameworkCore.Migrations.Internal
+Imports Microsoft.EntityFrameworkCore.SqlServer.Design.Internal
+Imports Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal
+Imports Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal
+Imports Microsoft.EntityFrameworkCore.Storage
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.EntityFrameworkCore.TestUtilities
+Imports Microsoft.EntityFrameworkCore.ValueGeneration
+Imports Microsoft.Extensions.DependencyInjection
+Imports NetTopologySuite
+Imports NetTopologySuite.Geometries
+Imports Xunit
+Imports Xunit.Sdk
+
+Namespace Migrations.Design
+ Partial Public Class VisualBasicMigrationsGeneratorTests
+
+
+ Public Sub Snapshots_compile()
+ Dim generator = CreateMigrationsCodeGenerator()
+
+ Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
+ modelBuilder.Model.RemoveAnnotation(CoreAnnotationNames.ProductVersion)
+ modelBuilder.Entity(Of EntityWithConstructorBinding)(
+ Sub(x)
+ x.Property(Function(e) e.Id)
+
+ x.Property(Of Guid)("PropertyWithValueGenerator").HasValueGenerator(Of GuidValueGenerator)()
+ End Sub)
+ modelBuilder.HasDbFunction(Function() MyDbFunction())
+
+ Dim model = modelBuilder.Model
+ model.Item("Some:EnumValue") = RegexOptions.Multiline
+
+ Dim entityType = model.AddEntityType("Cheese")
+ Dim property1 = entityType.AddProperty("Pickle", GetType(StringBuilder))
+ property1.SetValueConverter(
+ New ValueConverter(Of StringBuilder, String)(
+ Function(v) v.ToString(),
+ Function(v) New StringBuilder(v),
+ New ConverterMappingHints(size:=10)))
+
+ Dim property2 = entityType.AddProperty("Ham", GetType(RawEnum))
+ property2.SetValueConverter(
+ New ValueConverter(Of RawEnum, String)(
+ Function(v) v.ToString(),
+ Function(v) DirectCast([Enum].Parse(GetType(RawEnum), v), RawEnum),
+ New ConverterMappingHints(size:=10)))
+
+ entityType.SetPrimaryKey(property2)
+
+ Dim finalizedModel = modelBuilder.FinalizeModel(designTime:=True)
+
+ Dim modelSnapshotCode = generator.GenerateSnapshot(
+ "MyNamespace",
+ GetType(MyContext),
+ "MySnapshot",
+ finalizedModel)
+
+ Assert.Equal(
+
+Imports System
+Imports System.Text.RegularExpressions
+Imports EntityFrameworkCore.VisualBasic.Migrations.Design
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+
+Namespace Global.MyNamespace
+
+ Partial Class MySnapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
+ modelBuilder.HasAnnotation("Some:EnumValue", RegexOptions.Multiline)
+
+ modelBuilder.Entity("Cheese",
+ Sub(b)
+ b.Property(Of String)("Ham").
+ HasColumnType("just_string(10)")
+
+ b.Property(Of String)("Pickle").
+ HasColumnType("just_string(10)")
+
+ b.HasKey("Ham")
+
+ b.ToTable("Cheese")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithConstructorBinding",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("default_int_mapping")
+
+ b.Property(Of Guid)("PropertyWithValueGenerator").
+ HasColumnType("default_guid_mapping")
+
+ b.HasKey("Id")
+
+ b.ToTable("EntityWithConstructorBinding")
+ End Sub)
+ End Sub
+ End Class
+End Namespace
+]]>.Value, modelSnapshotCode, ignoreLineEndingDifferences:=True)
+
+ Dim snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot")
+ Assert.Equal(2, snapshot.Model.GetEntityTypes().Count())
+ End Sub
+
+
+ Public Sub Snapshot_with_default_values_are_round_tripped()
+ Dim generator = CreateMigrationsCodeGenerator()
+
+ Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
+ modelBuilder.Entity(Of EntityWithEveryPrimitive)(
+ Sub(eb)
+ eb.Property(Function(e) e.Boolean).HasDefaultValue(False)
+ eb.Property(Function(e) e.Byte).HasDefaultValue(Byte.MinValue)
+ eb.Property(Function(e) e.ByteArray).HasDefaultValue(New Byte() {0})
+ eb.Property(Function(e) e.Char).HasDefaultValue("0"c)
+ eb.Property(Function(e) e.DateTime).HasDefaultValue(Date.MinValue)
+ eb.Property(Function(e) e.DateTimeOffset).HasDefaultValue(DateTimeOffset.MinValue)
+ eb.Property(Function(e) e.Decimal).HasDefaultValue(Decimal.MinValue)
+ eb.Property(Function(e) e.Double).HasDefaultValue(Double.MinValue) 'double.NegativeInfinity
+ eb.Property(Function(e) e.Enum).HasDefaultValue(Enum1.Default)
+ eb.Property(Function(e) e.Guid).HasDefaultValue(Guid.NewGuid())
+ eb.Property(Function(e) e.Int16).HasDefaultValue(Short.MaxValue)
+ eb.Property(Function(e) e.Int32).HasDefaultValue(Integer.MaxValue)
+ eb.Property(Function(e) e.Int64).HasDefaultValue(Long.MaxValue)
+ eb.Property(Function(e) e.Single).HasDefaultValue(Single.Epsilon)
+ eb.Property(Function(e) e.SByte).HasDefaultValue(SByte.MinValue)
+ eb.Property(Function(e) e.String).HasDefaultValue("""")
+ eb.Property(Function(e) e.TimeSpan).HasDefaultValue(TimeSpan.MaxValue)
+ eb.Property(Function(e) e.UInt16).HasDefaultValue(UShort.MinValue)
+ eb.Property(Function(e) e.UInt32).HasDefaultValue(UInteger.MinValue)
+ eb.Property(Function(e) e.UInt64).HasDefaultValue(ULong.MinValue)
+ eb.Property(Function(e) e.NullableBoolean).HasDefaultValue(True)
+ eb.Property(Function(e) e.NullableByte).HasDefaultValue(Byte.MaxValue)
+ eb.Property(Function(e) e.NullableChar).HasDefaultValue("'"c)
+ eb.Property(Function(e) e.NullableDateTime).HasDefaultValue(DateTime.MaxValue)
+ eb.Property(Function(e) e.NullableDateTimeOffset).HasDefaultValue(DateTimeOffset.MaxValue)
+ eb.Property(Function(e) e.NullableDecimal).HasDefaultValue(Decimal.MaxValue)
+ eb.Property(Function(e) e.NullableDouble).HasDefaultValue(0.6822871999174)
+ eb.Property(Function(e) e.NullableEnum).HasDefaultValue(Enum1.One Or Enum1.Two)
+ eb.Property(Function(e) e.NullableStringEnum).HasDefaultValue(Enum1.One).HasConversion(Of String)()
+ eb.Property(Function(e) e.NullableGuid).HasDefaultValue(New Guid())
+ eb.Property(Function(e) e.NullableInt16).HasDefaultValue(Short.MinValue)
+ eb.Property(Function(e) e.NullableInt32).HasDefaultValue(Integer.MinValue)
+ eb.Property(Function(e) e.NullableInt64).HasDefaultValue(Long.MinValue)
+ eb.Property(Function(e) e.NullableSingle).HasDefaultValue(0.3333333F)
+ eb.Property(Function(e) e.NullableSByte).HasDefaultValue(SByte.MinValue)
+ eb.Property(Function(e) e.NullableTimeSpan).HasDefaultValue(TimeSpan.MinValue.Add(New TimeSpan()))
+ eb.Property(Function(e) e.NullableUInt16).HasDefaultValue(UShort.MaxValue)
+ eb.Property(Function(e) e.NullableUInt32).HasDefaultValue(UInteger.MaxValue)
+ eb.Property(Function(e) e.NullableUInt64).HasDefaultValue(ULong.MaxValue)
+
+ eb.HasKey(Function(e) e.Boolean)
+ End Sub)
+
+ Dim finalizedModel = modelBuilder.FinalizeModel(designTime:=True)
+
+ Dim modelSnapshotCode = generator.GenerateSnapshot(
+ "MyNamespace",
+ GetType(MyContext),
+ "MySnapshot",
+ finalizedModel)
+
+ Dim snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot")
+ Dim entityType = snapshot.Model.GetEntityTypes().Single()
+ Assert.Equal(GetType(EntityWithEveryPrimitive).FullName & " (Dictionary)", entityType.DisplayName())
+
+ For Each [property] In modelBuilder.Model.GetEntityTypes().Single().GetProperties()
+ Dim expected = [property].GetDefaultValue()
+ Dim actual = entityType.FindProperty([property].Name).GetDefaultValue()
+
+ If actual IsNot Nothing AndAlso expected IsNot Nothing Then
+ If expected.GetType().IsEnum Then
+ If TypeOf actual Is String Then
+ actual = [Enum].Parse(expected.GetType(), actual.ToString())
+ Else
+ actual = [Enum].ToObject(expected.GetType(), actual)
+ End If
+ End If
+
+ If actual.GetType() <> expected.GetType() Then
+ actual = Convert.ChangeType(actual, expected.GetType())
+ End If
+ End If
+
+ Assert.Equal(expected, actual)
+ Next
+ End Sub
+
+ Private Class EntityWithEveryPrimitive
+ Public Property [Boolean] As Boolean
+ Public Property [Byte] As Byte
+ Public Property ByteArray As Byte()
+ Public Property [Char] As Char
+ Public Property [DateTime] As DateTime
+ Public Property DateTimeOffset As DateTimeOffset
+ Public Property [Decimal] As Decimal
+ Public Property [Double] As Double
+ Public Property [Enum] As Enum1
+ Public Property StringEnum As Enum1
+ Public Property Guid As Guid
+ Public Property Int16 As Short
+ Public Property Int32 As Integer
+ Public Property Int64 As Long
+ Public Property NullableBoolean As Boolean?
+ Public Property NullableByte As Byte?
+ Public Property NullableChar As Char?
+ Public Property NullableDateTime As DateTime?
+ Public Property NullableDateTimeOffset As DateTimeOffset?
+ Public Property NullableDecimal As Decimal?
+ Public Property NullableDouble As Double?
+ Public Property NullableEnum As Enum1?
+ Public Property NullableStringEnum As Enum1?
+ Public Property NullableGuid As Guid?
+ Public Property NullableInt16 As Short?
+ Public Property NullableInt32 As Integer?
+ Public Property NullableInt64 As Long?
+ Public Property NullableSByte As SByte?
+ Public Property NullableSingle As Single?
+ Public Property NullableTimeSpan As TimeSpan?
+ Public Property NullableUInt16 As UShort?
+ Public Property NullableUInt32 As UInteger?
+ Public Property NullableUInt64 As ULong?
+ Public Property PrivateSetter As Integer
+ Get
+ Return 1
+ End Get
+ Private Set
+ End Set
+ End Property
+ Public Property [SByte] As SByte
+ Public Property [Single] As Single
+ Public Property [String] As String
+ Public Property TimeSpan As TimeSpan
+ Public Property UInt16 As UShort
+ Public Property UInt32 As UInteger
+ Public Property UInt64 As ULong
+ End Class
+
+
+ Public Enum Enum1
+ [Default] = 0
+ One = 1
+ Two = 2
+ End Enum
+
+ Private Class EntityWithManyProperties
+ Public Property Id As Integer
+ Public Property [String] As String
+ Public Property Bytes As Byte()
+ Public Property Int16 As Short
+ Public Property Int32 As Integer
+ Public Property Int64 As Long
+ Public Property [Double] As Double
+ Public Property [Decimal] As Decimal
+ Public Property DateTime As Date
+ Public Property DateTimeOffset As DateTimeOffset
+ Public Property TimeSpan As TimeSpan
+ Public Property [Single] As Single
+ Public Property [Boolean] As Boolean
+ Public Property [Byte] As Byte
+ Public Property UnsignedInt16 As UShort
+ Public Property UnsignedInt32 As UInteger
+ Public Property UnsignedInt64 As ULong
+ Public Property Character As Char
+ Public Property SignedByte As SByte
+ Public Property Enum64 As Enum64
+ Public Property Enum32 As Enum32
+ Public Property Enum16 As Enum16
+ Public Property Enum8 As Enum8
+ Public Property EnumU64 As EnumU64
+ Public Property EnumU32 As EnumU32
+ Public Property EnumU16 As EnumU16
+ Public Property EnumS8 As EnumS8
+ Public Property SpatialBGeometryCollection As Geometry
+ Public Property SpatialBLineString As Geometry
+ Public Property SpatialBMultiLineString As Geometry
+ Public Property SpatialBMultiPoint As Geometry
+ Public Property SpatialBMultiPolygon As Geometry
+ Public Property SpatialBPoint As Geometry
+ Public Property SpatialBPolygon As Geometry
+ Public Property SpatialCGeometryCollection As GeometryCollection
+ Public Property SpatialCLineString As LineString
+ Public Property SpatialCMultiLineString As MultiLineString
+ Public Property SpatialCMultiPoint As MultiPoint
+ Public Property SpatialCMultiPolygon As MultiPolygon
+ Public Property SpatialCPoint As Point
+ Public Property SpatialCPolygon As Polygon
+ Public Property Int32Collection As Integer()
+ Public Property DoubleCollection As Double()
+ Public Property StringCollection As String()
+ Public Property DateTimeCollection As Date()
+ Public Property BoolCollection As Boolean()
+ Public Property BytesCollection As Byte()()
+ End Class
+
+ Private Enum Enum64 As Long
+ SomeValue = 1
+ End Enum
+
+ Private Enum Enum32
+ SomeValue = 1
+ End Enum
+
+ Private Enum Enum16 As Short
+ SomeValue = 1
+ End Enum
+
+ Private Enum Enum8 As Byte
+ SomeValue = 1
+ End Enum
+
+ Private Enum EnumU64 As ULong
+ SomeValue = 1234567890123456789UL
+ End Enum
+
+ Private Enum EnumU32 As UInteger
+ SomeValue = UInteger.MaxValue
+ End Enum
+
+ Private Enum EnumU16 As UShort
+ SomeValue = UShort.MaxValue
+ End Enum
+
+ Private Enum EnumS8 As SByte
+ SomeValue = SByte.MinValue
+ End Enum
+
+ Private Class EntityWithOneProperty
+ Public Property Id As Integer
+ Public Property EntityWithTwoProperties As EntityWithTwoProperties
+ End Class
+
+ Private Class EntityWithTwoProperties
+
+ Public Property Id As Integer
+
+ Public Property AlternateId As Integer
+ Public Property EntityWithOneProperty As EntityWithOneProperty
+
+
+ Public Property EntityWithStringKey As EntityWithStringKey
+ End Class
+
+ Private Class EntityWithStringProperty
+ Public Property Id As Integer
+ Public Property Name As String
+
+
+ Public Property EntityWithOneProperty As EntityWithOneProperty
+ End Class
+
+ Private Class EntityWithDecimalProperty
+ Public Property Id As Integer
+ Public Property Price As Decimal
+ End Class
+
+ Private Class EntityWithStringKey
+ Public Property Id As String
+ Public Property Properties As ICollection(Of EntityWithStringProperty)
+ End Class
+
+ Private Class EntityWithStringAlternateKey
+ Public Property Id As Integer
+ Public Property AlternateId As String
+ Public Property Properties As ICollection(Of EntityWithStringProperty)
+ End Class
+
+ Private Class EntityWithGenericKey(Of TKey)
+ Public Property Id As Guid
+ End Class
+
+ Private Class EntityWithGenericProperty(Of TProperty)
+ Public Property Id As Integer
+ Public Property [Property] As TProperty
+ End Class
+
+ Private Class EntityWithThreeProperties
+ Public Property Id As Integer
+ Public Property X As Integer
+ Public Property Y As Integer
+ Public Property Z As Integer
+ End Class
+
+
+ Private Class EntityWithIndexAttribute
+ Public Property Id As Integer
+ Public Property FirstName As String
+ Public Property LastName As String
+ End Class
+
+
+ Private Class EntityWithNamedIndexAttribute
+ Public Property Id As Integer
+ Public Property FirstName As String
+ Public Property LastName As String
+ End Class
+
+
+ Private Class EntityWithUniqueIndexAttribute
+ Public Property Id As Integer
+ Public Property FirstName As String
+ Public Property LastName As String
+ End Class
+
+ Public Class TestOwner
+ Public Property Id As Integer
+ Public Property OwnedEntities As ICollection(Of TestOwnee)
+ End Class
+
+ Public Class TestOwnee
+ Public Property Id As Integer
+ Public Property TestEnum As TestEnum
+ End Class
+
+ Public Enum TestEnum
+ Value0 = 0
+ Value1
+ Value2
+ End Enum
+
+ Private MustInherit Class AbstractBase
+ Public Property Id As Integer
+ End Class
+
+ Private Class BaseEntity
+ Inherits AbstractBase
+
+ Public Property Discriminator As String
+ End Class
+
+ Private Class DerivedEntity
+ Inherits BaseEntity
+
+ Public Property Name As String
+ End Class
+
+ Private Class DuplicateDerivedEntity
+ Inherits BaseEntity
+
+ Public Property Name As String
+ End Class
+
+ Private Class AnotherDerivedEntity
+ Inherits BaseEntity
+
+ Public Property Title As String
+ End Class
+
+ Private Structure StructDiscriminator
+ Public ReadOnly Property Value As String
+ Sub New(value As String)
+ Me.Value = value
+ End Sub
+ End Structure
+
+ Private Class BaseEntityWithStructDiscriminator
+ Public Property Id As Integer
+
+ Public Property Discriminator As StructDiscriminator
+ End Class
+
+ Private Class DerivedEntityWithStructDiscriminator
+ Inherits BaseEntityWithStructDiscriminator
+ Public Property Name As String
+ End Class
+
+ Private Class AnotherDerivedEntityWithStructDiscriminator
+ Inherits BaseEntityWithStructDiscriminator
+
+ Public Property Title As String
+ End Class
+
+ Private Class BaseType
+ Public Property Id As Integer
+
+ Public Property Navigation As EntityWithOneProperty
+ End Class
+
+ Private Class DerivedType
+ Inherits BaseType
+ End Class
+
+ Private Enum Days As Long
+ Sun
+ Mon
+ Tue
+ Wed
+ Thu
+ Fri
+ Sat
+ End Enum
+
+ Private Class EntityWithEnumType
+ Public Property Id As Integer
+ Public Property Day As Days
+ End Class
+
+ Private Class EntityWithNullableEnumType
+ Public Property Id As Integer
+ Public Property Day As Days?
+ End Class
+
+ Private Class ManyToManyLeft
+ Public Property Id As Integer
+ Public Property Name As String
+ Public Property Rights As List(Of ManyToManyRight)
+ End Class
+
+ Private Class ManyToManyRight
+ Public Property Id As Integer
+ Public Property Description As String
+ Public Property Lefts As List(Of ManyToManyLeft)
+ End Class
+
+ Private Class CustomValueGenerator
+ Inherits ValueGenerator(Of Integer)
+
+ Public Overrides Function [Next](entry As EntityEntry) As Integer
+ Throw New NotImplementedException()
+ End Function
+
+ Public Overrides ReadOnly Property GeneratesTemporaryValues As Boolean
+ Get
+ Return False
+ End Get
+ End Property
+ End Class
+
+ Private MustInherit Class Animal
+ Public Property Id As Integer
+ Public Property Name As String
+ End Class
+
+ Private MustInherit Class Pet
+ Inherits Animal
+
+ Public Property Vet As String
+ Public ReadOnly Property Humans As ICollection(Of Human) = New List(Of Human)()
+ End Class
+
+ Private Class Cat
+ Inherits Pet
+
+ Public Property EducationLevel As String
+ End Class
+
+ Private Class Dog
+ Inherits Pet
+
+ Public Property FavoriteToy As String
+ End Class
+
+ Private Class Human
+ Inherits Animal
+
+ Public Property FavoriteAnimal As Animal
+ Public ReadOnly Property Pets As ICollection(Of Pet) = New List(Of Pet)()
+ End Class
+
+ Public MustInherit Class BarBase
+ Public Property Id As Integer
+ End Class
+
+ Public Class BarA
+ Inherits BarBase
+ End Class
+
+ Public Class FooExtension(Of T As BarBase)
+ Public Property Id As Integer
+
+ Public Property Bar As T
+ End Class
+
+ Public Class Parrot(Of TChild)
+ Public Property Id As Integer
+ Public Property Name As String
+ Public Property Child As TChild
+ End Class
+
+ Public Class Parrot
+ Public Property Id As Integer
+ Public Property Name As String
+ Public Property Child As Beak
+ End Class
+
+ Public Class Beak
+ Public Property Name As String
+ End Class
+
+#Region "Model"
+
+ Public Overridable Sub Model_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.HasAnnotation("AnnotationName", "AnnotationValue").
+ HasDatabaseMaxSize("100 MB").
+ HasServiceTier("basic").
+ HasPerformanceLevel("S0")
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(9, o.GetAnnotations().Count())
+ Assert.Equal("AnnotationValue", o("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Model_Fluent_APIs_are_properly_generated()
+ Test(
+ Sub(builder)
+ builder.UseHiLo()
+ builder.Entity(Of EntityWithOneProperty)()
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(SqlServerValueGenerationStrategy.SequenceHiLo, o.GetValueGenerationStrategy())
+ Assert.Equal(
+ SqlServerValueGenerationStrategy.SequenceHiLo,
+ o.GetEntityTypes().Single().GetProperty("Id").GetValueGenerationStrategy())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Model_fluent_APIs_for_sequence_key_are_properly_generated()
+ Test(
+ Sub(builder)
+ builder.UseKeySequences()
+ builder.Entity(Of EntityWithOneProperty)()
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(SqlServerValueGenerationStrategy.Sequence, o.GetValueGenerationStrategy())
+ Assert.Equal(
+ SqlServerValueGenerationStrategy.Sequence,
+ o.GetEntityTypes().Single().GetProperty("Id").GetValueGenerationStrategy())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Model_default_schema_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.HasDefaultSchema("DefaultSchema")
+ builder.HasAnnotation("AnnotationName", "AnnotationValue")
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(6, o.GetAnnotations().Count())
+ Assert.Equal("AnnotationValue", o("AnnotationName"))
+ Assert.Equal("DefaultSchema", o(RelationalAnnotationNames.DefaultSchema))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Entities_are_stored_in_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().Ignore(Function(e) e.EntityWithTwoProperties)
+ builder.Entity(Of EntityWithTwoProperties)().Ignore(Function(e) e.EntityWithOneProperty)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(2, o.GetEntityTypes().Count())
+ Assert.Collection(
+ o.GetEntityTypes(),
+ Sub(t) Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty", t.Name),
+ Sub(t) Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithTwoProperties", t.Name))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Entities_are_stored_in_model_snapshot_for_TPT()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().
+ ToTable("DerivedEntity", "foo")
+ builder.Entity(Of BaseEntity)()
+ builder.Entity(Of AbstractBase)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+ Assert.Equal(3, o.GetEntityTypes().Count())
+
+ Dim AbstractBase = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+AbstractBase")
+ Assert.Equal("AbstractBase", AbstractBase.GetTableName())
+ Assert.Equal("TPT", AbstractBase.GetMappingStrategy())
+
+ Dim BaseType = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BaseEntity")
+ Assert.Equal("BaseEntity", BaseType.GetTableName())
+ Assert.Equal("DefaultSchema", BaseType.GetSchema())
+
+ Dim derived = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+DerivedEntity")
+ Assert.Equal("DerivedEntity", derived.GetTableName())
+ Assert.Equal("foo", derived.GetSchema())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Entities_are_stored_in_model_snapshot_for_TPT_with_one_excluded()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().
+ ToTable("DerivedEntity", "foo", Function(t) t.ExcludeFromMigrations())
+ builder.Entity(Of BaseEntity)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+
+ Assert.Equal(
+ "DerivedEntity",
+ o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+DerivedEntity").
+ GetTableName())
+ End Sub)
+ End Sub
+
+
+ Public Sub Views_are_stored_in_the_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().Ignore(Function(e) e.EntityWithTwoProperties).ToView("EntityWithOneProperty")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("EntityWithOneProperty", o.GetEntityTypes().Single().GetViewName())
+ End Sub)
+ End Sub
+
+
+ Public Sub Views_with_schemas_are_stored_in_the_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ Ignore(Function(e) e.EntityWithTwoProperties).
+ ToView("EntityWithOneProperty", "ViewSchema")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("EntityWithOneProperty", o.GetEntityTypes().Single().GetViewName())
+ Assert.Equal("ViewSchema", o.GetEntityTypes().Single().GetViewSchema())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Entities_are_stored_in_model_snapshot_for_TPC()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().
+ ToTable("DerivedEntity", "foo").
+ ToView("DerivedView", "foo")
+
+ builder.Entity(Of BaseEntity)()
+ builder.Entity(Of AbstractBase)().UseTpcMappingStrategy()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(6, o.GetAnnotations().Count())
+ Assert.Equal(3, o.GetEntityTypes().Count())
+
+ Dim abstractBase = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+AbstractBase")
+ Assert.Null(abstractBase.GetTableName())
+ Assert.Null(abstractBase.GetViewName())
+ Assert.Equal("TPC", abstractBase.GetMappingStrategy())
+
+ Dim baseType = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BaseEntity")
+ Assert.Equal("BaseEntity", baseType.GetTableName())
+ Assert.Null(baseType.GetViewName())
+
+ Dim derived = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+DerivedEntity")
+ Assert.Equal("DerivedEntity", derived.GetTableName())
+ Assert.Equal("DerivedView", derived.GetViewName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Non_base_abstract_base_class_with_TPC()
+ Test(
+ Sub(builder)
+ builder.Entity(Of Animal)().UseTpcMappingStrategy()
+ builder.Entity(Of Pet)()
+ builder.Entity(Of Cat)()
+ builder.Entity(Of Dog)()
+ builder.Entity(Of Human)()
+ End Sub,
+
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+
+Namespace Global.RootNamespace
+
+ Partial Class Snapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
+ modelBuilder.
+ HasDefaultSchema("DefaultSchema").
+ HasAnnotation("Relational:MaxIdentifierLength", 128)
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
+
+ modelBuilder.HasSequence("AnimalSequence")
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Animal",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int").
+ HasDefaultValueSql("NEXT VALUE FOR [DefaultSchema].[AnimalSequence]")
+
+ SqlServerPropertyBuilderExtensions.UseSequence(b.Property(Of Integer)("Id"))
+
+ b.Property(Of String)("Name").
+ HasColumnType("nvarchar(max)")
+
+ b.HasKey("Id")
+
+ b.ToTable(DirectCast(Nothing, String))
+
+ b.UseTpcMappingStrategy()
+ End Sub)
+
+ modelBuilder.Entity("HumanPet",
+ Sub(b)
+ b.Property(Of Integer)("HumansId").
+ HasColumnType("int")
+
+ b.Property(Of Integer)("PetsId").
+ HasColumnType("int")
+
+ b.HasKey("HumansId", "PetsId")
+
+ b.HasIndex("PetsId")
+
+ b.ToTable("HumanPet", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Human",
+ Sub(b)
+ b.HasBaseType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Animal")
+
+ b.Property(Of Integer?)("FavoriteAnimalId").
+ HasColumnType("int")
+
+ b.HasIndex("FavoriteAnimalId")
+
+ b.ToTable("Human", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Pet",
+ Sub(b)
+ b.HasBaseType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Animal")
+
+ b.Property(Of String)("Vet").
+ HasColumnType("nvarchar(max)")
+
+ b.ToTable(DirectCast(Nothing, String))
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Cat",
+ Sub(b)
+ b.HasBaseType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Pet")
+
+ b.Property(Of String)("EducationLevel").
+ HasColumnType("nvarchar(max)")
+
+ b.ToTable("Cat", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Dog",
+ Sub(b)
+ b.HasBaseType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Pet")
+
+ b.Property(Of String)("FavoriteToy").
+ HasColumnType("nvarchar(max)")
+
+ b.ToTable("Dog", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("HumanPet",
+ Sub(b)
+ b.HasOne("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Human", Nothing).
+ WithMany().
+ HasForeignKey("HumansId").
+ OnDelete(DeleteBehavior.Cascade).
+ IsRequired()
+
+ b.HasOne("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Pet", Nothing).
+ WithMany().
+ HasForeignKey("PetsId").
+ OnDelete(DeleteBehavior.Cascade).
+ IsRequired()
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Human",
+ Sub(b)
+ b.HasOne("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Animal", "FavoriteAnimal").
+ WithMany().
+ HasForeignKey("FavoriteAnimalId")
+
+ b.Navigation("FavoriteAnimal")
+ End Sub)
+ End Sub
+ End Class
+End Namespace
+]]>.Value,
+ Sub(o)
+ Assert.Equal(6, o.GetAnnotations().Count())
+ Assert.Equal(6, o.GetEntityTypes().Count())
+
+ Dim animalType =
+ o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Animal")
+ Assert.Null(animalType.GetTableName())
+ Assert.Null(animalType.GetViewName())
+ Assert.Equal("TPC", animalType.GetMappingStrategy())
+
+ Dim petType = o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Pet")
+ Assert.Null(petType.GetTableName())
+ Assert.Null(petType.GetViewName())
+
+ Dim catType = o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Cat")
+ Assert.Equal("Cat", catType.GetTableName())
+ Assert.Null(catType.GetViewName())
+
+ Dim dogType = o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Dog")
+ Assert.Equal("Dog", dogType.GetTableName())
+ Assert.Null(dogType.GetViewName())
+
+ Dim humanType = o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Human")
+ Assert.Equal("Human", humanType.GetTableName())
+ Assert.Null(humanType.GetViewName())
+
+ Dim humanPetType = o.FindEntityType("HumanPet")
+ Assert.Equal("HumanPet", humanPetType.GetTableName())
+ Assert.Null(humanPetType.GetViewName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Abstract_base_class_with_TPT()
+ Test(
+ Sub(builder)
+ builder.Entity(Of Cat)().ToTable("Cats")
+ builder.Entity(Of Dog)().ToTable("Dogs")
+ builder.Entity(Of Animal)()
+ builder.Ignore(Of Human)()
+ builder.Ignore(Of Pet)()
+ builder.Ignore(Of Animal)()
+ End Sub,
+
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+
+Namespace Global.RootNamespace
+
+ Partial Class Snapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
+ modelBuilder.
+ HasDefaultSchema("DefaultSchema").
+ HasAnnotation("Relational:MaxIdentifierLength", 128)
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Cat",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.Property(Of String)("EducationLevel").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of String)("Name").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of String)("Vet").
+ HasColumnType("nvarchar(max)")
+
+ b.HasKey("Id")
+
+ b.ToTable("Cats", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Dog",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.Property(Of String)("FavoriteToy").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of String)("Name").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of String)("Vet").
+ HasColumnType("nvarchar(max)")
+
+ b.HasKey("Id")
+
+ b.ToTable("Dogs", "DefaultSchema")
+ End Sub)
+ End Sub
+ End Class
+End Namespace
+]]>.Value,
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+ Assert.Equal(2, o.GetEntityTypes().Count())
+
+ Dim catType = o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Cat")
+ Assert.Equal("Cats", catType.GetTableName())
+ Assert.Null(catType.GetViewName())
+ Assert.Null(catType.FindProperty("Discriminator"))
+
+ Dim dogType = o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Dog")
+ Assert.Equal("Dogs", dogType.GetTableName())
+ Assert.Null(dogType.GetViewName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Entity_splitting_is_stored_in_snapshot_with_tables()
+ Test(
+ Sub(builder)
+ builder.Entity(Of Order)(
+ Sub(b)
+ b.Ignore(Function(e) e.OrderInfo)
+
+ b.Property(Of Integer)("Shadow").HasColumnName("Shadow")
+ b.ToTable(
+ "Order",
+ "DefaultSchema",
+ Sub(tb)
+ tb.Property(Function(e) e.Id).UseIdentityColumn(2, 3).HasAnnotation("fii", "arr")
+ tb.Property("Shadow")
+ End Sub)
+
+ b.SplitToTable(
+ "SplitOrder",
+ "DefaultSchema",
+ Sub(sb)
+ sb.Property("Shadow")
+ sb.HasTrigger("splitTrigger").HasAnnotation("oof", "rab")
+ sb.HasAnnotation("foo", "bar")
+ End Sub)
+
+ b.OwnsOne(
+ Function(p) p.OrderBillingDetails,
+ Sub(od)
+ od.OwnsOne(Function(c) c.StreetAddress)
+
+ od.Property(Of Integer)("BillingShadow")
+ od.ToTable(
+ "SplitOrder",
+ "DefaultSchema",
+ Sub(tb)
+ tb.Property("BillingShadow").HasColumnName("Shadow")
+ End Sub)
+ od.SplitToTable(
+ "BillingDetails",
+ "DefaultSchema",
+ Sub(sb)
+ sb.Property("BillingShadow").HasColumnName("Shadow")
+ End Sub)
+ End Sub)
+
+ b.OwnsOne(
+ Function(p) p.OrderShippingDetails,
+ Sub(od)
+ od.OwnsOne(Function(c) c.StreetAddress).ToTable("ShippingDetails")
+
+ od.Property(Of Integer)("ShippingShadow")
+ od.ToTable(
+ "Order",
+ "DefaultSchema",
+ Sub(tb)
+ tb.Property("ShippingShadow").HasColumnName("Shadow")
+ End Sub)
+ od.SplitToTable(
+ "ShippingDetails",
+ "DefaultSchema",
+ Sub(sb)
+ sb.Property("ShippingShadow")
+ End Sub)
+ End Sub)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Assert.Equal(5, model.GetEntityTypes().Count())
+
+ Dim orderEntityType = model.FindEntityType(GetType(Order))
+ Assert.Equal(NameOf(Order), orderEntityType.GetTableName())
+
+ Dim id = orderEntityType.FindProperty("Id")
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, id.GetValueGenerationStrategy())
+ Assert.Equal(1, id.GetIdentitySeed())
+ Assert.Equal(1, id.GetIdentityIncrement())
+
+ Dim [overrides] = id.FindOverrides(StoreObjectIdentifier.Create(orderEntityType, StoreObjectType.Table).Value)
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, [overrides].GetValueGenerationStrategy())
+ Assert.Equal(2, [overrides].GetIdentitySeed())
+ Assert.Equal(3, [overrides].GetIdentityIncrement())
+ Assert.Equal("arr", [overrides]("fii"))
+
+ Dim billingOwnership = orderEntityType.FindNavigation(NameOf(Order.OrderBillingDetails)).
+ ForeignKey
+ Dim billingEntityType = billingOwnership.DeclaringEntityType
+ Assert.Equal("SplitOrder", billingEntityType.GetTableName())
+
+ Dim billingAddressOwnership = billingEntityType.FindNavigation(NameOf(OrderDetails.StreetAddress)).
+ ForeignKey
+ Dim billingAddress = billingAddressOwnership.DeclaringEntityType
+ Assert.Equal("SplitOrder", billingAddress.GetTableName())
+
+ Dim shippingOwnership = orderEntityType.FindNavigation(NameOf(Order.OrderShippingDetails)).
+ ForeignKey
+ Dim shippingEntityType = shippingOwnership.DeclaringEntityType
+ Assert.Equal(NameOf(Order), shippingEntityType.GetTableName())
+
+ Dim shippingAddressOwnership = shippingEntityType.FindNavigation(NameOf(OrderDetails.StreetAddress)).
+ ForeignKey
+ Dim shippingAddress = shippingAddressOwnership.DeclaringEntityType
+ Assert.Equal("ShippingDetails", shippingAddress.GetTableName())
+
+ Dim relationalModel = model.GetRelationalModel()
+
+ Assert.Equal(4, relationalModel.Tables.Count())
+
+ Dim orderTable = relationalModel.FindTable(orderEntityType.GetTableName(), orderEntityType.GetSchema())
+ Assert.Equal(
+ {orderEntityType, shippingEntityType},
+ orderTable.FindColumn("Shadow").PropertyMappings.Select(Function(m) m.TableMapping.TypeBase))
+
+ Dim fragment = orderEntityType.GetMappingFragments().Single()
+ Dim splitTable = relationalModel.FindTable(fragment.StoreObject.Name, fragment.StoreObject.Schema)
+ Assert.Equal(
+ {orderEntityType, billingEntityType},
+ splitTable.FindColumn("Shadow").PropertyMappings.Select(Function(m) m.TableMapping.TypeBase))
+ Assert.Equal("bar", fragment("foo"))
+
+ Dim trigger = orderEntityType.GetDeclaredTriggers().Single()
+ Assert.Equal(splitTable.Name, trigger.GetTableName())
+ Assert.Equal(splitTable.Schema, trigger.GetTableSchema())
+ Assert.Equal("rab", trigger("oof"))
+
+ Dim billingFragment = billingEntityType.GetMappingFragments().Single()
+ Dim billingTable = relationalModel.FindTable(billingFragment.StoreObject.Name, billingFragment.StoreObject.Schema)
+ Assert.Equal(
+ {billingEntityType},
+ billingTable.FindColumn("Shadow").PropertyMappings.Select(Function(m) m.TableMapping.TypeBase))
+
+ Dim shippingFragment = shippingEntityType.GetMappingFragments().Single()
+ Dim shippingTable = relationalModel.FindTable(shippingFragment.StoreObject.Name, shippingFragment.StoreObject.Schema)
+ Assert.Equal(
+ {shippingEntityType},
+ shippingTable.FindColumn("ShippingShadow").PropertyMappings.Select(Function(m) m.TableMapping.TypeBase))
+
+ Assert.Equal({"Id", "Shadow"}, orderTable.Columns.Select(Function(c) c.Name))
+ Assert.Equal({"Id", "OrderBillingDetails_StreetAddress_City", "Shadow"}, splitTable.Columns.Select(Function(c) c.Name))
+ Assert.Equal({"OrderId", "Shadow"}, billingTable.Columns.Select(Function(c) c.Name))
+ Assert.Equal({"OrderId", "ShippingShadow", "StreetAddress_City"}, shippingTable.Columns.Select(Function(c) c.Name))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Entity_splitting_is_stored_in_snapshot_with_views()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)(
+ Sub(b)
+ b.Property(Of Integer)("Shadow")
+ b.ToView(
+ "EntityWithOneProperty",
+ Sub(tb)
+ tb.Property("Shadow")
+ End Sub)
+ b.SplitToView(
+ "SplitView",
+ Sub(sb)
+ sb.Property("Shadow")
+ End Sub)
+
+ b.OwnsOne(
+ Function(eo) eo.EntityWithTwoProperties,
+ Sub(eb)
+ eb.Ignore(Function(e) e.EntityWithStringKey)
+
+ eb.ToView(
+ "EntityWithOneProperty",
+ Sub(tb)
+ tb.Property(Function(e) e.AlternateId).HasColumnName("SomeId")
+ End Sub)
+ eb.SplitToView(
+ "SplitView",
+ Sub(sb)
+ sb.Property(Function(e) e.AlternateId).HasColumnName("SomeOtherId")
+ End Sub)
+ End Sub)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim entityWithOneProperty1 = model.FindEntityType(GetType(EntityWithOneProperty))
+ Assert.Equal(NameOf(EntityWithOneProperty), entityWithOneProperty1.GetViewName())
+
+ Dim ownership = entityWithOneProperty1.FindNavigation(NameOf(EntityWithOneProperty.EntityWithTwoProperties)).
+ ForeignKey
+ Dim ownedType = ownership.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithOneProperty), ownedType.GetViewName())
+
+ Dim relationalModel = model.GetRelationalModel()
+
+ Assert.Empty(relationalModel.Tables)
+ Assert.Equal(2, relationalModel.Views.Count())
+
+ Dim mainView = relationalModel.FindView(entityWithOneProperty1.GetViewName(), "DefaultSchema")
+
+ Dim fragment = entityWithOneProperty1.GetMappingFragments().Single()
+ Dim splitView = relationalModel.FindView(fragment.StoreObject.Name, fragment.StoreObject.Schema)
+
+ Assert.Equal({"Id", "Shadow", "SomeId"}, mainView.Columns.Select(Function(c) c.Name))
+ Assert.Equal({"Id", "Shadow", "SomeOtherId"}, splitView.Columns.Select(Function(c) c.Name))
+ End Sub)
+ End Sub
+
+
+ Public Sub Unmapped_entity_types_are_stored_in_the_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.HasDefaultSchema("default")
+ builder.Entity(Of EntityWithOneProperty)().Ignore(Function(e) e.EntityWithTwoProperties).ToTable(DirectCast(Nothing, String)).
+ UpdateUsingStoredProcedure("Update", "sproc", Sub(p) p.HasParameter(Function(e) e.Id))
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Null(o.GetEntityTypes().Single().GetTableName())
+ Assert.Null(o.GetEntityTypes().Single().GetSchema())
+ End Sub)
+ End Sub
+
+ Private Class TestKeylessType
+ Public Property Something As String
+ End Class
+
+ Private Shared Function GetCountByYear(id As Integer) As IQueryable(Of TestKeylessType)
+ Throw New NotImplementedException()
+ End Function
+
+
+ Public Sub TVF_types_are_stored_in_the_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.HasDbFunction(
+ GetType(VisualBasicMigrationsGeneratorTests).GetMethod(
+ NameOf(GetCountByYear),
+ BindingFlags.NonPublic Or BindingFlags.Static))
+
+ builder.Entity(Of TestKeylessType)().HasNoKey().ToTable(DirectCast(Nothing, String))
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim entityType = o.GetEntityTypes().Single()
+ Assert.Null(entityType.GetFunctionName())
+ Assert.Null(entityType.GetTableName())
+ End Sub)
+ End Sub
+
+
+ Public Sub Entity_types_mapped_to_functions_are_stored_in_the_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of TestKeylessType)(
+ Sub(kb)
+ kb.Property(Function(k) k.Something)
+ kb.HasNoKey().ToFunction("GetCount")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("GetCount", o.GetEntityTypes().Single().GetFunctionName())
+ End Sub)
+ End Sub
+
+
+ Public Sub Entity_types_mapped_to_queries_are_stored_in_the_model_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ Ignore(Function(e) e.EntityWithTwoProperties).
+ ToSqlQuery("query")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("query", o.GetEntityTypes().Single().GetSqlQuery())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Sequence_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.HasSequence(Of Integer)("Foo", "Bar").
+ StartsAt(2).
+ HasMin(1).
+ HasMax(3).
+ IncrementsBy(2).
+ IsCyclic().
+ HasAnnotation("foo", "bar")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(6, o.GetAnnotations().Count())
+
+ Dim sequence = o.GetSequences().Single()
+ Assert.Equal(2, sequence.StartValue)
+ Assert.Equal(1, sequence.MinValue)
+ Assert.Equal(3, sequence.MaxValue)
+ Assert.Equal(2, sequence.IncrementBy)
+ Assert.True(sequence.IsCyclic)
+ Assert.Equal("bar", sequence("foo"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub HiLoSequence_with_default_model_schema()
+ Test(
+ Sub(builder)
+ builder.HasDefaultSchema("dbo").
+ Entity("Entity").Property(Of Integer)("Id").UseHiLo(schema:="dbo")
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal("dbo", o.GetDefaultSchema())
+
+ Dim sequence = Assert.Single(o.GetSequences())
+ Assert.Equal("dbo", sequence.Schema)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub CheckConstraint_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().ToTable(
+ Sub(tb)
+ tb.HasCheckConstraint("AlternateId", "AlternateId > Id").
+ HasName("CK_Customer_AlternateId").
+ HasAnnotation("foo", "bar")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ Id").
+ HasName("CK_Customer_AlternateId").
+ HasAnnotation("foo", "bar")
+ End Sub)
+ End Sub)
+]]>.Value),
+ Sub(o)
+ Dim constraint = o.GetEntityTypes().Single().GetCheckConstraints().Single()
+ Assert.Equal("CK_Customer_AlternateId", constraint.Name)
+ Assert.Equal("bar", constraint("foo"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub CheckConstraint_is_only_stored_in_snapshot_once_for_TPH()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().
+ ToTable(Sub(tb) tb.HasCheckConstraint("CK_BaseEntity_AlternateId", "AlternateId > Id"))
+ builder.Entity(Of BaseEntity)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ Id")
+ End Sub)
+
+ b.HasDiscriminator().HasValue("DerivedEntity")
+ End Sub)
+]]>.Value),
+ Sub(o)
+ Dim constraint = o.FindEntityType(GetType(DerivedEntity)).GetDeclaredCheckConstraints().Single()
+ Assert.Equal("CK_BaseEntity_AlternateId", constraint.Name)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Trigger_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ ToTable(
+ Sub(tb)
+ tb.HasTrigger("SomeTrigger").HasAnnotation("foo", "bar").HasDatabaseName("SomeTrg")
+ End Sub)
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim trigger = Assert.Single(o.GetEntityTypes().Single().GetDeclaredTriggers())
+ Assert.Equal("SomeTrigger", trigger.ModelName)
+ Assert.Equal("SomeTrg", trigger.GetDatabaseName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Triggers_and_ExcludeFromMigrations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ ToTable(
+ Sub(tb)
+ tb.HasTrigger("SomeTrigger1")
+ tb.HasTrigger("SomeTrigger2")
+ tb.ExcludeFromMigrations()
+ End Sub)
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim entityType = Assert.Single(o.GetEntityTypes())
+
+ Assert.True(entityType.IsTableExcludedFromMigrations())
+
+ Assert.Collection(
+ entityType.GetDeclaredTriggers(),
+ Sub(t) Assert.Equal("SomeTrigger1", t.GetDatabaseName()),
+ Sub(t) Assert.Equal("SomeTrigger2", t.GetDatabaseName()))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ProductVersion_is_stored_in_snapshot()
+ Dim modelBuilder = CreateConventionalModelBuilder()
+ Dim generator = CreateMigrationsGenerator()
+ Dim code = generator.GenerateSnapshot("RootNamespace", GetType(DbContext), "Snapshot", DirectCast(modelBuilder.Model, IModel))
+ Assert.Contains(" HasAnnotation(""ProductVersion"",", code)
+
+ Dim modelFromSnapshot = BuildModelFromSnapshotSource(code)
+ Assert.Equal(ProductInfo.GetVersion(), modelFromSnapshot.GetProductVersion())
+ End Sub
+
+
+ Public Overridable Sub Model_use_identity_columns()
+ Test(
+ Sub(builder) builder.UseIdentityColumns(),
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, o.GetValueGenerationStrategy())
+ Assert.Equal(1, o.GetIdentitySeed())
+ Assert.Equal(1, o.GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Model_use_identity_columns_custom_seed()
+ Test(
+ Sub(builder)
+ builder.UseIdentityColumns(5)
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, o.GetValueGenerationStrategy())
+ Assert.Equal(5, o.GetIdentitySeed())
+ Assert.Equal(1, o.GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Model_use_identity_columns_custom_increment()
+ Test(
+ Sub(builder)
+ builder.UseIdentityColumns(increment:=5)
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, o.GetValueGenerationStrategy())
+ Assert.Equal(1, o.GetIdentitySeed())
+ Assert.Equal(5, o.GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Model_use_identity_columns_custom_seed_increment()
+ Test(
+ Sub(builder)
+ builder.UseIdentityColumns(Long.MaxValue, 5)
+ builder.Entity(
+ "Building",
+ Sub(b)
+ b.Property(Of Integer)("Id")
+
+ b.HasKey("Id")
+
+ b.ToTable("Buildings", "DefaultSchema")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(5, o.GetAnnotations().Count())
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, o.GetValueGenerationStrategy())
+ Assert.Equal(Long.MaxValue, o.GetIdentitySeed())
+ Assert.Equal(5, o.GetIdentityIncrement())
+
+ Dim [property] = o.FindEntityType("Building").FindProperty("Id")
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, [property].GetValueGenerationStrategy())
+ Assert.Equal(Long.MaxValue, [property].GetIdentitySeed())
+ Assert.Equal(5, [property].GetIdentityIncrement())
+ End Sub)
+ End Sub
+#End Region
+
+#Region "EntityType"
+
+ Public Overridable Sub EntityType_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().HasAnnotation("AnnotationName", "AnnotationValue")
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(3, o.GetEntityTypes().First().GetAnnotations().Count())
+ Assert.Equal("AnnotationValue", o.GetEntityTypes().First()("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub EntityType_Fluent_APIs_are_properly_generated()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().ToTable(Sub(tb) tb.IsMemoryOptimized())
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().Single().IsMemoryOptimized())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub BaseType_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().HasBaseType(Of BaseEntity)()
+ builder.Entity(Of AnotherDerivedEntity)().HasBaseType(Of BaseEntity)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(3, o.GetEntityTypes().Count())
+ Assert.Collection(
+ o.GetEntityTypes(),
+ Sub(t) Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+AnotherDerivedEntity", t.Name),
+ Sub(t) Assert.Equal("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BaseEntity", t.Name),
+ Sub(t) Assert.Equal("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+DerivedEntity", t.Name)
+ )
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Discriminator_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().HasBaseType(Of BaseEntity)()
+ builder.Entity(Of AnotherDerivedEntity)().HasBaseType(Of BaseEntity)()
+ builder.Entity(Of BaseEntity)().
+ HasDiscriminator(Function(e) e.Discriminator).
+ IsComplete().
+ HasValue(GetType(BaseEntity), GetType(BaseEntity).Name).
+ HasValue(GetType(DerivedEntity), GetType(DerivedEntity).Name).
+ HasValue(GetType(AnotherDerivedEntity), GetType(AnotherDerivedEntity).Name)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("Discriminator", o.FindEntityType(GetType(BaseEntity))(CoreAnnotationNames.DiscriminatorProperty))
+ Assert.Equal("BaseEntity", o.FindEntityType(GetType(BaseEntity))(CoreAnnotationNames.DiscriminatorValue))
+ Assert.Equal(
+ "AnotherDerivedEntity",
+ o.FindEntityType(GetType(AnotherDerivedEntity))(CoreAnnotationNames.DiscriminatorValue))
+ Assert.Equal("DerivedEntity", o.FindEntityType(GetType(DerivedEntity))(CoreAnnotationNames.DiscriminatorValue))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Converted_discriminator_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntityWithStructDiscriminator)().HasBaseType(Of BaseEntityWithStructDiscriminator)()
+ builder.Entity(Of AnotherDerivedEntityWithStructDiscriminator)().HasBaseType(Of BaseEntityWithStructDiscriminator)()
+ builder.Entity(Of BaseEntityWithStructDiscriminator)(
+ Sub(b)
+ b.Property(Function(e) e.Discriminator).
+ HasConversion(
+ Function(v) v.Value,
+ Function(v) New StructDiscriminator(v))
+ b.HasDiscriminator(Function(e) e.Discriminator).
+ IsComplete().
+ HasValue(GetType(BaseEntityWithStructDiscriminator), New StructDiscriminator("Base")).
+ HasValue(GetType(DerivedEntityWithStructDiscriminator), New StructDiscriminator("Derived")).
+ HasValue(GetType(AnotherDerivedEntityWithStructDiscriminator), New StructDiscriminator("Another"))
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "Discriminator",
+ o.FindEntityType(GetType(BaseEntityWithStructDiscriminator))(CoreAnnotationNames.DiscriminatorProperty))
+
+ Assert.Equal(
+ "Base",
+ o.FindEntityType(GetType(BaseEntityWithStructDiscriminator))(CoreAnnotationNames.DiscriminatorValue))
+
+ Assert.Equal(
+ "Another",
+ o.FindEntityType(GetType(AnotherDerivedEntityWithStructDiscriminator))(CoreAnnotationNames.DiscriminatorValue))
+
+ Assert.Equal(
+ "Derived",
+ o.FindEntityType(GetType(DerivedEntityWithStructDiscriminator))(CoreAnnotationNames.DiscriminatorValue))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Properties_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(2, o.GetEntityTypes().First().GetProperties().Count())
+ Assert.Collection(
+ o.GetEntityTypes().First().GetProperties(),
+ Sub(t) Assert.Equal("Id", t.Name),
+ Sub(t) Assert.Equal("AlternateId", t.Name)
+ )
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Primary_key_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasKey(
+ Function(t) New With {t.Id, t.AlternateId})
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(2, o.GetEntityTypes().First().FindPrimaryKey().Properties.Count)
+ Assert.Collection(
+ o.GetEntityTypes().First().FindPrimaryKey().Properties,
+ Sub(t) Assert.Equal("Id", t.Name),
+ Sub(t) Assert.Equal("AlternateId", t.Name)
+ )
+ End Sub)
+ End Sub
+
+
+ Public Sub HasNoKey_is_handled()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithOneProperty)().Ignore(Function(e) e.EntityWithTwoProperties).HasNoKey(),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim entityType = Assert.Single(o.GetEntityTypes())
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty", entityType.Name)
+ Assert.Null(entityType.FindPrimaryKey())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Alternate_keys_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasAlternateKey(
+ Function(t) New With {t.Id, t.AlternateId})
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Collection(
+ o.GetEntityTypes().First().GetDeclaredKeys().First(Function(k) k.Properties.Count = 2).Properties,
+ Sub(t) Assert.Equal("Id", t.Name),
+ Sub(t) Assert.Equal("AlternateId", t.Name)
+ )
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Indexes_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(Function(t) t.AlternateId)
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Single(o.GetEntityTypes().First().GetIndexes())
+ Assert.Equal("AlternateId", o.GetEntityTypes().First().GetIndexes().First().Properties(0).Name)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Indexes_are_stored_in_snapshot_including_composite_index()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(
+ Function(t) New With {t.Id, t.AlternateId})
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Single(o.GetEntityTypes().First().GetIndexes())
+ Assert.Collection(
+ o.GetEntityTypes().First().GetIndexes().First().Properties,
+ Sub(t) Assert.Equal("Id", t.Name),
+ Sub(t) Assert.Equal("AlternateId", t.Name))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Foreign_keys_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.
+ Entity(Of EntityWithTwoProperties)().
+ HasOne(Function(e) e.EntityWithOneProperty).
+ WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim foreignKey = o.FindEntityType(GetType(EntityWithTwoProperties)).GetForeignKeys().Single()
+ Assert.Equal("AlternateId", foreignKey.Properties(0).Name)
+ Assert.Equal("EntityWithTwoProperties", foreignKey.PrincipalToDependent.Name)
+ Assert.Equal("EntityWithOneProperty", foreignKey.DependentToPrincipal.Name)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Many_to_many_join_table_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.
+ Entity(Of ManyToManyLeft)().
+ ToTable("ManyToManyLeft", "schema").
+ HasMany(Function(l) l.Rights).
+ WithMany(Function(r) r.Lefts)
+
+ builder.
+ Entity(Of ManyToManyRight)().
+ ToTable("ManyToManyRight", "schema")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(Model)
+ Dim joinEntity = Model.FindEntityType("ManyToManyLeftManyToManyRight")
+ Assert.Equal(GetType(Dictionary(Of String, Object)), joinEntity.ClrType)
+ Assert.Collection(
+ joinEntity.GetDeclaredProperties(),
+ Sub(p)
+ Assert.Equal("LeftsId", p.Name)
+ Assert.False(p.IsShadowProperty())
+ End Sub,
+ Sub(p)
+ Assert.Equal("RightsId", p.Name)
+ Assert.False(p.IsShadowProperty())
+ End Sub)
+ Assert.Collection(
+ joinEntity.FindDeclaredPrimaryKey().Properties,
+ Sub(p)
+ Assert.Equal("LeftsId", p.Name)
+ End Sub,
+ Sub(p)
+ Assert.Equal("RightsId", p.Name)
+ End Sub)
+ Assert.Collection(
+ joinEntity.GetDeclaredForeignKeys(),
+ Sub(fk)
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+ManyToManyLeft",
+ fk.PrincipalEntityType.Name)
+ Assert.Collection(
+ fk.PrincipalKey.Properties,
+ Sub(p)
+ Assert.Equal("Id", p.Name)
+ End Sub)
+ Assert.Collection(
+ fk.Properties,
+ Sub(p)
+ Assert.Equal("LeftsId", p.Name)
+ End Sub)
+ End Sub,
+ Sub(fk)
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+ManyToManyRight",
+ fk.PrincipalEntityType.Name)
+ Assert.Collection(
+ fk.PrincipalKey.Properties,
+ Sub(p)
+ Assert.Equal("Id", p.Name)
+ End Sub)
+ Assert.Collection(
+ fk.Properties,
+ Sub(p)
+ Assert.Equal("RightsId", p.Name)
+ End Sub)
+ End Sub)
+
+ Assert.Equal("ManyToManyLeftManyToManyRight", joinEntity.GetTableName())
+ Assert.Equal("schema", joinEntity.GetSchema())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Can_override_table_name_for_many_to_many_join_table_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ Dim manyToMany = builder.
+ Entity(Of ManyToManyLeft)().
+ HasMany(Function(l) l.Rights).
+ WithMany(Function(r) r.Lefts).
+ UsingEntity(Function(a) a.ToTable("MyJoinTable"))
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim joinEntity = o.FindEntityType("ManyToManyLeftManyToManyRight")
+ Assert.Equal(GetType(Dictionary(Of String, Object)), joinEntity.ClrType)
+ Assert.Equal("MyJoinTable", joinEntity.GetTableName())
+ Assert.Collection(
+ joinEntity.GetDeclaredProperties(),
+ Sub(p)
+ Assert.Equal("LeftsId", p.Name)
+ Assert.False(p.IsShadowProperty())
+ Assert.True(p.IsIndexerProperty())
+ End Sub,
+ Sub(p)
+ Assert.Equal("RightsId", p.Name)
+ Assert.False(p.IsShadowProperty())
+ Assert.True(p.IsIndexerProperty())
+ End Sub)
+ Assert.Collection(
+ joinEntity.FindDeclaredPrimaryKey().Properties,
+ Sub(p)
+ Assert.Equal("LeftsId", p.Name)
+ End Sub,
+ Sub(p)
+ Assert.Equal("RightsId", p.Name)
+ End Sub)
+ Assert.Collection(
+ joinEntity.GetDeclaredForeignKeys(),
+ Sub(fk)
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+ManyToManyLeft",
+ fk.PrincipalEntityType.Name)
+ Assert.Collection(
+ fk.PrincipalKey.Properties,
+ Sub(p)
+ Assert.Equal("Id", p.Name)
+ End Sub)
+ Assert.Collection(
+ fk.Properties,
+ Sub(p)
+ Assert.Equal("LeftsId", p.Name)
+ End Sub)
+ End Sub,
+ Sub(fk)
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+ManyToManyRight",
+ fk.PrincipalEntityType.Name)
+ Assert.Collection(
+ fk.PrincipalKey.Properties,
+ Sub(p)
+ Assert.Equal("Id", p.Name)
+ End Sub)
+ Assert.Collection(
+ fk.Properties,
+ Sub(p)
+ Assert.Equal("RightsId", p.Name)
+ End Sub)
+ End Sub)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub TableName_preserved_when_generic()
+ Dim originalModel As IReadOnlyModel = Nothing
+
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithGenericKey(Of Guid))()
+
+ originalModel = builder.Model
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ ",
+ Sub(b)
+ b.Property(Of Guid)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("uniqueidentifier")
+
+ b.HasKey("Id")
+
+ b.ToTable("EntityWithGenericKey", "DefaultSchema")
+ End Sub)
+]]>.Value, importsSystem:=True),
+ Sub(model)
+ Dim originalEntity = originalModel.FindEntityType(GetType(EntityWithGenericKey(Of Guid)))
+ Dim entity = model.FindEntityType(originalEntity.Name)
+
+ Assert.NotNull(entity)
+ Assert.Equal(originalEntity.GetTableName(), entity.GetTableName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Shared_columns_are_stored_in_the_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)(
+ Sub(b)
+ b.ToTable("EntityWithProperties")
+ b.Property(Of Integer)("AlternateId").HasColumnName("AlternateId")
+ End Sub)
+ builder.Entity(Of EntityWithTwoProperties)(
+ Sub(b)
+ b.ToTable("EntityWithProperties")
+ b.Property(Function(e) e.AlternateId).HasColumnName("AlternateId")
+ b.HasOne(Function(e) e.EntityWithOneProperty).WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.Id)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsSystem:=False),
+ Sub(o)
+ Dim entityType = o.FindEntityType(GetType(EntityWithOneProperty))
+
+ Assert.Equal(ValueGenerated.OnUpdateSometimes, entityType.FindProperty("AlternateId").ValueGenerated)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub PrimaryKey_name_preserved_when_generic()
+ Dim originalModel As IReadOnlyModel = Nothing
+
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithGenericKey(Of Guid))()
+
+ originalModel = builder.Model
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ ",
+ Sub(b)
+ b.Property(Of Guid)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("uniqueidentifier")
+
+ b.HasKey("Id")
+
+ b.ToTable("EntityWithGenericKey", "DefaultSchema")
+ End Sub)
+]]>.Value, importsSystem:=True),
+ Sub(model)
+ Dim originalEntity = originalModel.FindEntityType(GetType(EntityWithGenericKey(Of Guid)))
+ Dim entity = model.FindEntityType(originalEntity.Name)
+ Assert.NotNull(entity)
+
+ Dim originalPrimaryKey = originalEntity.FindPrimaryKey()
+ Dim primaryKey = entity.FindPrimaryKey()
+
+ Assert.Equal(originalPrimaryKey.GetName(), primaryKey.GetName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub AlternateKey_name_preserved_when_generic()
+ Dim originalModel As IReadOnlyModel = Nothing
+
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithGenericProperty(Of Guid))().HasAlternateKey(Function(e) e.Property)
+
+ originalModel = builder.Model
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ ",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.Property(Of Guid)("Property").
+ HasColumnType("uniqueidentifier")
+
+ b.HasKey("Id")
+
+ b.HasAlternateKey("Property")
+
+ b.ToTable("EntityWithGenericProperty", "DefaultSchema")
+ End Sub)
+]]>.Value, importsSystem:=True),
+ Sub(Model)
+ Dim originalEntity = originalModel.FindEntityType(GetType(EntityWithGenericProperty(Of Guid)))
+ Dim entity = Model.FindEntityType(originalEntity.Name)
+ Assert.NotNull(entity)
+
+ Dim originalAlternateKey = originalEntity.FindKey(originalEntity.FindProperty("Property"))
+ Dim alternateKey = entity.FindKey(entity.FindProperty("Property"))
+
+ Assert.Equal(originalAlternateKey.GetName(), alternateKey.GetName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Discriminator_of_enum()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithEnumType)().HasDiscriminator(Function(e) e.Day),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(Model)
+ Assert.Equal(GetType(Long), Model.GetEntityTypes().First().FindDiscriminatorProperty().ClrType)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Discriminator_of_enum_to_string()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithEnumType)(
+ Sub(x)
+ x.Property(Function(e) e.Day).HasConversion(Of String)()
+
+ x.HasDiscriminator(Function(e) e.Day)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim discriminatorProperty = model.GetEntityTypes().First().FindDiscriminatorProperty()
+ Assert.Equal(GetType(String), discriminatorProperty.ClrType)
+ Assert.False(discriminatorProperty.IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Temporal_table_information_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().ToTable(
+ Sub(tb)
+ tb.IsTemporal(
+ Sub(ttb)
+ ttb.UseHistoryTable("HistoryTable")
+ ttb.HasPeriodStart("Start").HasColumnName("PeriodStart")
+ ttb.HasPeriodEnd("End").HasColumnName("PeriodEnd")
+ End Sub)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsSystem:=True),
+ Sub(o)
+ Dim temporalEntity = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithStringProperty")
+ Dim annotations = temporalEntity.GetAnnotations().ToList()
+
+ Assert.Equal(7, annotations.Count)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Return a.Name = SqlServerAnnotationNames.IsTemporal AndAlso
+ CType(a.Value, Boolean?).HasValue AndAlso
+ CType(a.Value, Boolean?).Value
+ End Function)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Return a.Name = SqlServerAnnotationNames.TemporalHistoryTableName AndAlso
+ CStr(a.Value) = "HistoryTable"
+ End Function)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Dim value = TryCast(a.Value, String)
+ Return a.Name = SqlServerAnnotationNames.TemporalPeriodStartPropertyName AndAlso
+ CStr(a.Value) = "Start"
+ End Function)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Dim value = TryCast(a.Value, String)
+ Return a.Name = SqlServerAnnotationNames.TemporalPeriodEndPropertyName AndAlso
+ CStr(a.Value) = "End"
+ End Function)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Temporal_table_information_is_stored_in_snapshot_minimal_setup()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().ToTable(
+ Sub(tb)
+ tb.IsTemporal()
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsSystem:=True),
+ Sub(o)
+ Dim temporalEntity = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithStringProperty")
+ Dim annotations = temporalEntity.GetAnnotations().ToList()
+
+ Assert.Equal(7, annotations.Count)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Return a.Name = SqlServerAnnotationNames.IsTemporal AndAlso
+ CType(a.Value, Boolean?).HasValue AndAlso
+ CType(a.Value, Boolean?).Value
+ End Function)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Return a.Name = SqlServerAnnotationNames.TemporalPeriodStartPropertyName AndAlso
+ CStr(a.Value) = "PeriodStart"
+ End Function)
+ Assert.Contains(
+ annotations,
+ Function(a)
+ Return a.Name = SqlServerAnnotationNames.TemporalPeriodEndPropertyName AndAlso
+ CStr(a.Value) = "PeriodEnd"
+ End Function)
+ End Sub)
+ End Sub
+#End Region
+
+#Region "Owned types"
+
+ Public Overridable Sub Owned_types_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)(
+ Sub(b)
+ b.HasKey(Function(e) e.Id).HasName("PK_Custom")
+
+ b.OwnsOne(
+ Function(eo) eo.EntityWithTwoProperties,
+ Sub(eb)
+ eb.HasKey(Function(e) e.AlternateId).HasName("PK_Custom")
+
+ eb.WithOwner(Function(e) e.EntityWithOneProperty).
+ HasForeignKey(Function(e) e.AlternateId).
+ HasConstraintName("FK_Custom")
+
+ eb.HasIndex(Function(e) e.Id).
+ IncludeProperties(Function(e) e.AlternateId)
+
+ eb.HasOne(Function(e) e.EntityWithStringKey).WithOne()
+
+ eb.HasData(
+ New EntityWithTwoProperties With {.AlternateId = 1, .Id = -1})
+ End Sub)
+
+ b.HasData(
+ New EntityWithOneProperty With {.Id = 1})
+ End Sub)
+
+ builder.Entity(Of EntityWithStringKey)(
+ Sub(b)
+ b.OwnsMany(
+ Function(es) es.Properties,
+ Sub(es)
+ es.HasKey(Function(e) e.Id)
+ es.HasOne(Function(e) e.EntityWithOneProperty).WithOne()
+ End Sub)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim aEntityWithOneProperty = o.FindEntityType(GetType(EntityWithOneProperty))
+ Assert.Equal("PK_Custom", aEntityWithOneProperty.GetKeys().Single().GetName())
+ Assert.Equal(New Object() {1}, aEntityWithOneProperty.GetSeedData().Single().Values)
+
+ Dim ownership1 = aEntityWithOneProperty.FindNavigation(NameOf(EntityWithOneProperty.EntityWithTwoProperties)).ForeignKey
+ Assert.Equal(NameOf(EntityWithTwoProperties.AlternateId), ownership1.Properties(0).Name)
+ Assert.Equal(NameOf(EntityWithTwoProperties.EntityWithOneProperty), ownership1.DependentToPrincipal.Name)
+ Assert.True(ownership1.IsRequired)
+ Assert.Equal("FK_Custom", ownership1.GetConstraintName())
+ Dim ownedType1 = ownership1.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithTwoProperties.AlternateId), ownedType1.FindPrimaryKey().Properties(0).Name)
+ Assert.Equal("PK_Custom", ownedType1.GetKeys().Single().GetName())
+ Assert.Equal(2, ownedType1.GetIndexes().Count())
+ Dim owned1index1 = ownedType1.GetIndexes().First()
+ Assert.Equal("EntityWithStringKeyId", owned1index1.Properties(0).Name)
+ Assert.True(owned1index1.IsUnique)
+ Assert.Equal("[EntityWithTwoProperties_EntityWithStringKeyId] IS NOT NULL", owned1index1.GetFilter())
+ Assert.Null(owned1index1.GetIncludeProperties())
+ Dim owned1index2 = ownedType1.GetIndexes().Last()
+ Assert.Equal("Id", owned1index2.Properties(0).Name)
+ Assert.False(owned1index2.IsUnique)
+ Assert.Null(owned1index2.GetFilter())
+ Assert.Equal({NameOf(EntityWithTwoProperties.AlternateId)}, owned1index2.GetIncludeProperties())
+ Assert.Equal(New Object() {1, -1}, ownedType1.GetSeedData().Single().Values)
+ Assert.Equal(NameOf(EntityWithOneProperty), ownedType1.GetTableName())
+ Assert.False(ownedType1.IsTableExcludedFromMigrations())
+
+ Dim aEntityWithStringKey = o.FindEntityType(GetType(EntityWithStringKey))
+ Assert.Same(
+ aEntityWithStringKey,
+ ownedType1.FindNavigation(NameOf(EntityWithTwoProperties.EntityWithStringKey)).TargetEntityType)
+ Assert.Equal(NameOf(EntityWithStringKey), aEntityWithStringKey.GetTableName())
+
+ Dim ownership2 = aEntityWithStringKey.FindNavigation(NameOf(EntityWithStringKey.Properties)).ForeignKey
+ Assert.Equal("EntityWithStringKeyId", ownership2.Properties(0).Name)
+ Assert.Null(ownership2.DependentToPrincipal)
+ Assert.True(ownership2.IsRequired)
+ Dim ownedType2 = ownership2.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithStringProperty.Id), ownedType2.FindPrimaryKey().Properties(0).Name)
+ Assert.Single(ownedType2.GetKeys())
+ Assert.Equal(2, ownedType2.GetIndexes().Count())
+ Dim owned2index1 = ownedType2.GetIndexes().First()
+ Assert.Equal("EntityWithOnePropertyId", owned2index1.Properties(0).Name)
+ Assert.True(owned2index1.IsUnique)
+ Assert.Equal("[EntityWithOnePropertyId] IS NOT NULL", owned2index1.GetFilter())
+ Dim owned2index2 = ownedType2.GetIndexes().Last()
+ Assert.Equal("EntityWithStringKeyId", owned2index2.Properties(0).Name)
+ Assert.False(owned2index2.IsUnique)
+ Assert.Null(owned2index2.GetFilter())
+ Assert.Equal(NameOf(EntityWithStringProperty), ownedType2.GetTableName())
+ Assert.False(ownedType2.IsTableExcludedFromMigrations())
+
+ Assert.Same(aEntityWithOneProperty, ownedType2.GetNavigations().Single().TargetEntityType)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Owned_types_are_stored_in_snapshot_when_excluded()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)(
+ Sub(b)
+ b.HasKey(Function(e) e.Id).HasName("PK_Custom")
+
+ b.OwnsOne(
+ Function(eo) eo.EntityWithTwoProperties,
+ Sub(eb)
+ eb.HasKey(Function(e) e.AlternateId).HasName("PK_Custom")
+ eb.WithOwner(Function(e) e.EntityWithOneProperty).
+ HasForeignKey(Function(e) e.AlternateId).
+ HasConstraintName("FK_Custom")
+ eb.HasIndex(Function(e) e.Id)
+
+ eb.HasOne(Function(e) e.EntityWithStringKey).WithOne()
+
+ eb.HasData(
+ New EntityWithTwoProperties With {.AlternateId = 1, .Id = -1})
+ End Sub)
+
+ b.HasData(
+ New EntityWithOneProperty With {.Id = 1})
+
+ b.ToTable("EntityWithOneProperty", "DefaultSchema", Function(e) e.ExcludeFromMigrations())
+ End Sub)
+
+ builder.Entity(Of EntityWithStringKey)(
+ Sub(b)
+ b.OwnsMany(
+ Function(es) es.Properties,
+ Sub(es)
+ es.HasKey(Function(e) e.Id)
+ es.HasOne(Function(e) e.EntityWithOneProperty).WithOne()
+
+ es.ToTable("EntityWithStringProperty", Function(t) t.ExcludeFromMigrations())
+ End Sub)
+
+ b.ToTable("EntityWithStringKey", Function(e) e.ExcludeFromMigrations())
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim aEntityWithOneProperty = o.FindEntityType(GetType(EntityWithOneProperty))
+ Assert.Equal("PK_Custom", aEntityWithOneProperty.GetKeys().Single().GetName())
+ Assert.Equal(New Object() {1}, aEntityWithOneProperty.GetSeedData().Single().Values)
+
+ Dim ownership1 = aEntityWithOneProperty.FindNavigation(NameOf(EntityWithOneProperty.EntityWithTwoProperties)).ForeignKey
+ Assert.Equal(NameOf(EntityWithTwoProperties.AlternateId), ownership1.Properties(0).Name)
+ Assert.Equal(NameOf(EntityWithTwoProperties.EntityWithOneProperty), ownership1.DependentToPrincipal.Name)
+ Assert.True(ownership1.IsRequired)
+ Assert.Equal("FK_Custom", ownership1.GetConstraintName())
+ Dim ownedType1 = ownership1.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithTwoProperties.AlternateId), ownedType1.FindPrimaryKey().Properties(0).Name)
+ Assert.Equal("PK_Custom", ownedType1.GetKeys().Single().GetName())
+ Assert.Equal(2, ownedType1.GetIndexes().Count())
+ Dim owned1index1 = ownedType1.GetIndexes().First()
+ Assert.Equal("EntityWithStringKeyId", owned1index1.Properties(0).Name)
+ Assert.True(owned1index1.IsUnique)
+ Assert.Equal("[EntityWithTwoProperties_EntityWithStringKeyId] IS NOT NULL", owned1index1.GetFilter())
+ Dim owned1index2 = ownedType1.GetIndexes().Last()
+ Assert.Equal("Id", owned1index2.Properties(0).Name)
+ Assert.False(owned1index2.IsUnique)
+ Assert.Null(owned1index2.GetFilter())
+ Assert.Equal(New Object() {1, -1}, ownedType1.GetSeedData().Single().Values)
+ Assert.Equal(NameOf(EntityWithOneProperty), ownedType1.GetTableName())
+ Assert.True(ownedType1.IsTableExcludedFromMigrations())
+
+ Dim aEntityWithStringKey = o.FindEntityType(GetType(EntityWithStringKey))
+ Assert.Same(
+ aEntityWithStringKey,
+ ownedType1.FindNavigation(NameOf(EntityWithTwoProperties.EntityWithStringKey)).TargetEntityType)
+ Assert.Equal(NameOf(EntityWithStringKey), aEntityWithStringKey.GetTableName())
+ Assert.True(aEntityWithStringKey.IsTableExcludedFromMigrations())
+
+ Dim ownership2 = aEntityWithStringKey.FindNavigation(NameOf(EntityWithStringKey.Properties)).ForeignKey
+ Assert.Equal("EntityWithStringKeyId", ownership2.Properties(0).Name)
+ Assert.Null(ownership2.DependentToPrincipal)
+ Assert.True(ownership2.IsRequired)
+ Dim ownedType2 = ownership2.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithStringProperty.Id), ownedType2.FindPrimaryKey().Properties(0).Name)
+ Assert.Single(ownedType2.GetKeys())
+ Assert.Equal(2, ownedType2.GetIndexes().Count())
+ Dim owned2index1 = ownedType2.GetIndexes().First()
+ Assert.Equal("EntityWithOnePropertyId", owned2index1.Properties(0).Name)
+ Assert.True(owned2index1.IsUnique)
+ Assert.Equal("[EntityWithOnePropertyId] IS NOT NULL", owned2index1.GetFilter())
+ Dim owned2index2 = ownedType2.GetIndexes().Last()
+ Assert.Equal("EntityWithStringKeyId", owned2index2.Properties(0).Name)
+ Assert.False(owned2index2.IsUnique)
+ Assert.Null(owned2index2.GetFilter())
+ Assert.Equal(NameOf(EntityWithStringProperty), ownedType2.GetTableName())
+ Assert.True(ownedType2.IsTableExcludedFromMigrations())
+
+ Assert.Same(aEntityWithOneProperty, ownedType2.GetNavigations().Single().TargetEntityType)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Shared_owned_types_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of Order)().OwnsOne(Function(p) p.OrderBillingDetails, Sub(od) od.OwnsOne(Function(c) c.StreetAddress))
+ builder.Entity(Of Order)().OwnsOne(Function(p) p.OrderShippingDetails, Sub(od) od.OwnsOne(Function(c) c.StreetAddress))
+ builder.Entity(Of Order)().OwnsOne(Function(p) p.OrderInfo, Sub(od) od.OwnsOne(Function(c) c.StreetAddress))
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(7, o.GetEntityTypes().Count())
+
+ Dim anOrder = DirectCast(o.FindEntityType(GetType(Order).FullName), IRuntimeEntityType)
+ Assert.Equal(1, anOrder.PropertyCount)
+
+ Dim anOrderInfo = DirectCast(anOrder.FindNavigation(NameOf(Order.OrderInfo)).TargetEntityType, IRuntimeEntityType)
+ Assert.Equal(1, anOrderInfo.PropertyCount)
+
+ Dim orderInfoAddress = DirectCast(anOrderInfo.FindNavigation(NameOf(OrderInfo.StreetAddress)).TargetEntityType, IRuntimeEntityType)
+ Assert.Equal(2, orderInfoAddress.PropertyCount)
+
+ Dim orderBillingDetails = DirectCast(anOrder.FindNavigation(NameOf(Order.OrderBillingDetails)).TargetEntityType, IRuntimeEntityType)
+ Assert.Equal(1, orderBillingDetails.PropertyCount)
+
+ Dim orderBillingDetailsAddress =
+ DirectCast(orderBillingDetails.FindNavigation(NameOf(OrderDetails.StreetAddress)).TargetEntityType, IRuntimeEntityType)
+ Assert.Equal(2, orderBillingDetailsAddress.PropertyCount)
+
+ Dim orderShippingDetails = DirectCast(anOrder.FindNavigation(NameOf(Order.OrderShippingDetails)).TargetEntityType, IRuntimeEntityType)
+ Assert.Equal(1, orderShippingDetails.PropertyCount)
+
+ Dim orderShippingDetailsAddress =
+ DirectCast(orderShippingDetails.FindNavigation(NameOf(OrderDetails.StreetAddress)).TargetEntityType, IRuntimeEntityType)
+ Assert.Equal(2, orderShippingDetailsAddress.PropertyCount)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Owned_types_can_be_mapped_to_view()
+ Test(
+ Sub(builder)
+ builder.Entity(Of TestOwner)().OwnsMany(
+ Function(o) o.OwnedEntities,
+ Sub(ownee)
+ ownee.ToView("OwnedView")
+ End Sub)
+ End Sub,
+
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+
+Namespace Global.RootNamespace
+
+ Partial Class Snapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
+ modelBuilder.
+ HasDefaultSchema("DefaultSchema").
+ HasAnnotation("Relational:MaxIdentifierLength", 128)
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwner",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.HasKey("Id")
+
+ b.ToTable("TestOwner", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwner",
+ Sub(b)
+ b.OwnsMany("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwnee", "OwnedEntities",
+ Sub(b1)
+ b1.Property(Of Integer)("TestOwnerId").
+ HasColumnType("int")
+
+ b1.Property(Of Integer)("Id").
+ HasColumnType("int")
+
+ b1.Property(Of Integer)("TestEnum").
+ HasColumnType("int")
+
+ b1.HasKey("TestOwnerId", "Id")
+
+ b1.ToTable(DirectCast(Nothing, String))
+
+ b1.ToView("OwnedView", "DefaultSchema")
+
+ b1.WithOwner().
+ HasForeignKey("TestOwnerId")
+ End Sub)
+
+ b.Navigation("OwnedEntities")
+ End Sub)
+ End Sub
+ End Class
+End Namespace
+]]>.Value,
+ Sub(model)
+ Assert.Equal(2, model.GetEntityTypes().Count())
+ Dim testOwner = model.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwner")
+ Dim testOwnee = model.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwnee", "OwnedEntities", testOwner)
+ Assert.Equal("OwnedView", testOwnee.GetViewName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Snapshot_with_OwnedNavigationBuilder_HasCheckConstraint_compiles()
+ Test(
+ Sub(builder)
+ builder.Entity(Of TestOwner)().OwnsMany(
+ Function(o) o.OwnedEntities,
+ Sub(ownee)
+ ownee.ToTable(
+ Sub(tb)
+ tb.HasCheckConstraint("CK_TestOwnee_TestEnum_Enum_Constraint", "[TestEnum] IN (0, 1, 2)")
+ End Sub)
+ End Sub)
+ End Sub,
+
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+
+Namespace Global.RootNamespace
+
+ Partial Class Snapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
+ modelBuilder.
+ HasDefaultSchema("DefaultSchema").
+ HasAnnotation("Relational:MaxIdentifierLength", 128)
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwner",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.HasKey("Id")
+
+ b.ToTable("TestOwner", "DefaultSchema")
+ End Sub)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwner",
+ Sub(b)
+ b.OwnsMany("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwnee", "OwnedEntities",
+ Sub(b1)
+ b1.Property(Of Integer)("TestOwnerId").
+ HasColumnType("int")
+
+ b1.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property(Of Integer)("Id"))
+
+ b1.Property(Of Integer)("TestEnum").
+ HasColumnType("int")
+
+ b1.HasKey("TestOwnerId", "Id")
+
+ b1.ToTable("TestOwnee", "DefaultSchema",
+ Sub(t)
+ t.HasCheckConstraint("CK_TestOwnee_TestEnum_Enum_Constraint", "[TestEnum] IN (0, 1, 2)")
+ End Sub)
+
+ b1.WithOwner().
+ HasForeignKey("TestOwnerId")
+ End Sub)
+
+ b.Navigation("OwnedEntities")
+ End Sub)
+ End Sub
+ End Class
+End Namespace
+]]>.Value,
+ Sub(o)
+ Assert.Equal(2, o.GetEntityTypes().Count())
+ Dim testOwner = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwner")
+ Dim testOwnee = o.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+TestOwnee", "OwnedEntities", testOwner)
+ Assert.NotNull(testOwnee.FindCheckConstraint("CK_TestOwnee_TestEnum_Enum_Constraint"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Owned_types_mapped_to_json_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)(
+ Sub(b)
+ b.HasKey(Function(x) x.Id).HasName("PK_Custom")
+
+ b.OwnsOne(
+ Function(x) x.EntityWithTwoProperties,
+ Sub(bb)
+ bb.ToJson()
+ bb.Ignore(Function(x) x.Id)
+ bb.Property(Function(x) x.AlternateId).HasJsonPropertyName("NotKey")
+ bb.WithOwner(Function(e) e.EntityWithOneProperty)
+ bb.OwnsOne(
+ Function(x) x.EntityWithStringKey,
+ Sub(bbb)
+ bbb.Ignore(Function(x) x.Id)
+ bbb.OwnsMany(
+ Function(x) x.Properties,
+ Sub(bbbb) bbbb.HasJsonPropertyName("JsonProps"))
+ End Sub)
+ End Sub)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsSystem:=False),
+ Sub(o)
+ Dim anEntityWithOneProperty = o.FindEntityType(GetType(EntityWithOneProperty))
+ Assert.Equal("PK_Custom", anEntityWithOneProperty.GetKeys().Single().GetName())
+
+ Dim ownership1 = anEntityWithOneProperty.FindNavigation(NameOf(EntityWithOneProperty.EntityWithTwoProperties)).ForeignKey
+ Assert.Equal("EntityWithOnePropertyId", ownership1.Properties(0).Name)
+
+ Assert.Equal(NameOf(EntityWithTwoProperties.EntityWithOneProperty), ownership1.DependentToPrincipal.Name)
+ Assert.True(ownership1.IsRequired)
+ Assert.Equal("FK_EntityWithOneProperty_EntityWithOneProperty_EntityWithOnePropertyId", ownership1.GetConstraintName())
+ Dim ownedType1 = ownership1.DeclaringEntityType
+ Assert.Equal("EntityWithOnePropertyId", ownedType1.FindPrimaryKey().Properties(0).Name)
+
+ Dim ownedProperties1 = ownedType1.GetProperties().ToList()
+ Assert.Equal("EntityWithOnePropertyId", ownedProperties1(0).Name)
+ Assert.Equal("AlternateId", ownedProperties1(1).Name)
+ Assert.Equal("NotKey", Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetJsonPropertyName(ownedProperties1(1)))
+
+ Assert.Equal(NameOf(EntityWithOneProperty), ownedType1.GetTableName())
+ Assert.Equal("EntityWithTwoProperties", ownedType1.GetContainerColumnName())
+
+ Dim ownership2 = ownedType1.FindNavigation(NameOf(EntityWithStringKey)).ForeignKey
+ Assert.Equal("EntityWithTwoPropertiesEntityWithOnePropertyId", ownership2.Properties(0).Name)
+ Assert.Equal(NameOf(EntityWithTwoProperties.EntityWithStringKey), ownership2.PrincipalToDependent.Name)
+ Assert.True(ownership2.IsRequired)
+
+ Dim ownedType2 = ownership2.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithStringKey), ownedType2.DisplayName())
+ Assert.Equal("EntityWithTwoPropertiesEntityWithOnePropertyId", ownedType2.FindPrimaryKey().Properties(0).Name)
+
+ Dim ownedProperties2 = ownedType2.GetProperties().ToList()
+ Assert.Equal("EntityWithTwoPropertiesEntityWithOnePropertyId", ownedProperties2(0).Name)
+
+ Dim navigation3 = ownedType2.FindNavigation(NameOf(EntityWithStringKey.Properties))
+ Assert.Equal("JsonProps", navigation3.TargetEntityType.GetJsonPropertyName())
+ Dim ownership3 = navigation3.ForeignKey
+ Assert.Equal("EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId", ownership3.Properties(0).Name)
+ Assert.Equal(NameOf(EntityWithStringKey.Properties), ownership3.PrincipalToDependent.Name)
+ Assert.True(ownership3.IsRequired)
+ Assert.False(ownership3.IsUnique)
+
+ Dim ownedType3 = ownership3.DeclaringEntityType
+ Assert.Equal(NameOf(EntityWithStringProperty), ownedType3.DisplayName())
+ Dim pkProperties3 = ownedType3.FindPrimaryKey().Properties
+ Assert.Equal("EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId", pkProperties3(0).Name)
+ Assert.Equal("__synthesizedOrdinal", pkProperties3(1).Name)
+
+ Dim ownedProperties3 = ownedType3.GetProperties().ToList()
+ Assert.Equal(4, ownedProperties3.Count)
+
+ Assert.Equal("EntityWithStringKeyEntityWithTwoPropertiesEntityWithOnePropertyId", ownedProperties3(0).Name)
+ Assert.Equal("__synthesizedOrdinal", ownedProperties3(1).Name)
+ Assert.Equal("Id", ownedProperties3(2).Name)
+ Assert.Equal("Name", ownedProperties3(3).Name)
+ End Sub)
+ End Sub
+
+ Private Class Order
+ Public Property Id As Integer
+ Public Property OrderBillingDetails As OrderDetails
+ Public Property OrderShippingDetails As OrderDetails
+ Public Property OrderInfo As OrderInfo
+ End Class
+
+ Private Class OrderDetails
+ Public Property StreetAddress As StreetAddress
+ End Class
+
+ Private Class OrderInfo
+ Public Property StreetAddress As StreetAddress
+ End Class
+
+ Private Class StreetAddress
+ Public Property City As String
+ End Class
+#End Region
+
+#Region "Property"
+
+ Public Overridable Sub Property_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ Property(Of Integer)("Id").
+ HasAnnotation("AnnotationName", "AnnotationValue")
+
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("AnnotationValue", o.GetEntityTypes().First().FindProperty("Id")("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Custom_value_generator_is_ignored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().Property(Of Integer)("Id").HasValueGenerator(Of CustomValueGenerator)()
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Null(o.GetEntityTypes().First().FindProperty("Id")(CoreAnnotationNames.ValueGeneratorFactory))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_isNullable_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().Property(Of String)("Name").IsRequired()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.False(o.GetEntityTypes().First().FindProperty("Name").IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_ValueGenerated_value_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasDefaultValue()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsSystem:=True),
+ Sub(o)
+ Assert.Equal(ValueGenerated.OnAdd, o.GetEntityTypes().First().FindProperty("AlternateId").ValueGenerated)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_ValueGenerated_non_identity()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithEnumType)(
+ Sub(x)
+ x.Property(Function(e) e.Id).Metadata.SetValueGenerationStrategy(SqlServerValueGenerationStrategy.None)
+ x.Property(Function(e) e.Day).ValueGeneratedOnAdd().
+ Metadata.SetValueGenerationStrategy(SqlServerValueGenerationStrategy.None)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim id = model.GetEntityTypes().Single().GetProperty(NameOf(EntityWithEnumType.Id))
+ Assert.Equal(ValueGenerated.OnAdd, id.ValueGenerated)
+ Assert.Equal(SqlServerValueGenerationStrategy.None, id.GetValueGenerationStrategy())
+ Dim day = model.GetEntityTypes().Single().GetProperty(NameOf(EntityWithEnumType.Day))
+ Assert.Equal(ValueGenerated.OnAdd, day.ValueGenerated)
+ Assert.Equal(SqlServerValueGenerationStrategy.None, day.GetValueGenerationStrategy())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_maxLength_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().Property(Of String)("Name").HasMaxLength(100)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(100, o.GetEntityTypes().First().FindProperty("Name").GetMaxLength())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_maximum_maxLength_is_stored_in_snapshot()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithStringProperty)().Property(Of String)("Name").HasMaxLength(-1),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(-1, o.GetEntityTypes().First().FindProperty("Name").GetMaxLength())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_unicodeness_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().Property(Of String)("Name").IsUnicode(False)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.False(o.GetEntityTypes().First().FindProperty("Name").IsUnicode())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_fixedlengthness_is_stored_in_snapshot()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithStringProperty)().Property(Of String)("Name").IsFixedLength().HasMaxLength(100),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().First().FindProperty("Name").IsFixedLength())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_precision_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.
+ Entity(Of EntityWithDecimalProperty)().
+ Property(Of Decimal)(NameOf(EntityWithDecimalProperty.Price)).
+ HasPrecision(7)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.GetEntityTypes().First().FindProperty(NameOf(EntityWithDecimalProperty.Price))
+ Assert.Equal(7, [property].GetPrecision())
+ Assert.Null([property].GetScale())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_precision_and_scale_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.
+ Entity(Of EntityWithDecimalProperty)().
+ Property(Of Decimal)(NameOf(EntityWithDecimalProperty.Price)).
+ HasPrecision(7, 3)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.GetEntityTypes().First().FindProperty(NameOf(EntityWithDecimalProperty.Price))
+ Assert.Equal(7, [property].GetPrecision())
+ Assert.Equal(3, [property].GetScale())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Many_facets_chained_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().
+ Property(Of String)("Name").
+ HasMaxLength(100).
+ IsUnicode(False).
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.GetEntityTypes().First().FindProperty("Name")
+ Assert.Equal(100, [property].GetMaxLength())
+ Assert.False([property].IsUnicode())
+ Assert.Equal("AnnotationValue", [property]("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_concurrencyToken_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").IsConcurrencyToken()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().First().FindProperty("AlternateId").IsConcurrencyToken)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_column_name_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasColumnName("CName")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("CName", o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:ColumnName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_column_name_is_stored_in_snapshot_when_DefaultColumnName_uses_clr_type()
+ Test(
+ Sub(builder)
+ builder.
+ Entity(Of BarA)(Function(b) b.HasBaseType(Of BarBase)()).
+ Entity(Of FooExtension(Of BarA))(
+ Sub(b)
+ b.HasOne(Function(x) x.Bar).WithOne().HasForeignKey(Of BarA)()
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ ",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.HasKey("Id")
+
+ b.ToTable("FooExtension", "DefaultSchema")
+ End Sub)
+
+modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BarA",
+ Sub(b)
+ b.HasBaseType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BarBase")
+
+ b.Property(Of Integer?)("FooExtensionId").
+ HasColumnType("int").
+ HasColumnName("FooExtensionId")
+
+ b.HasIndex("FooExtensionId").
+ IsUnique().
+ HasFilter("[FooExtensionId] IS NOT NULL")
+
+ b.HasDiscriminator().HasValue("BarA")
+ End Sub)
+
+modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BarA",
+ Sub(b)
+ b.HasOne("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+FooExtension", Nothing).
+ WithOne("Bar").
+ HasForeignKey("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BarA", "FooExtensionId")
+ End Sub)
+
+modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+FooExtension",
+ Sub(b)
+ b.Navigation("Bar")
+ End Sub)
+]]>.Value),
+ Sub(model)
+ Dim entityType = model.FindEntityType(GetType(BarA).FullName)
+ Assert.NotNull(entityType)
+
+ Dim [property] = entityType.FindProperty("FooExtensionId")
+ Assert.NotNull([property])
+ Assert.Equal("FooExtensionId", [property].GetColumnName())
+
+ Assert.Collection(
+ model.GetRelationalModel().Tables,
+ Sub(t)
+ Assert.Equal("BarBase", t.Name)
+ Assert.Equal({"Id", "Discriminator", "FooExtensionId"}, t.Columns.Select(Function(tt) tt.Name))
+ End Sub,
+ Sub(t)
+ Assert.Equal("FooExtension", t.Name)
+ Assert.Equal({"Id"}, t.Columns.Select(Function(tt) tt.Name))
+ End Sub)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Generic_entity_type_with_owned_entities()
+ Test(
+ Sub(builder)
+ builder.Entity(Of Parrot(Of Beak))().OwnsOne(Function(e) e.Child)
+ End Sub,
+ AddBoilerPlate(
+ ",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.Property(Of String)("Name").
+ HasColumnType("nvarchar(max)")
+
+ b.HasKey("Id")
+
+ b.ToTable("Parrot", "DefaultSchema")
+ End Sub)
+
+modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Parrot",
+ Sub(b)
+ b.OwnsOne("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Beak", "Child",
+ Sub(b1)
+ b1.Property(Of Integer)("ParrotId").
+ HasColumnType("int")
+
+ b1.Property(Of String)("Name").
+ HasColumnType("nvarchar(max)")
+
+ b1.HasKey("ParrotId")
+
+ b1.ToTable("Parrot", "DefaultSchema")
+
+ b1.WithOwner().
+ HasForeignKey("ParrotId")
+ End Sub)
+
+ b.Navigation("Child")
+ End Sub)
+]]>.Value),
+ Sub(model)
+ Dim parentType = model.FindEntityType(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Parrot")
+ Assert.NotNull(parentType)
+ Assert.NotNull(parentType.FindNavigation("Child").TargetEntityType)
+
+ Dim table = model.GetRelationalModel().Tables.Single()
+ Assert.Equal({"Id", "Child_Name", "Name"}, table.Columns.Select(Function(t) t.Name))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Non_generic_entity_type_with_owned_entities()
+ Test(
+ Sub(builder)
+ builder.Entity(Of Parrot)().OwnsOne(Function(e) e.Child)
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Dim parentType =
+ o.FindEntityType("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+Parrot")
+ Assert.NotNull(parentType)
+ Assert.NotNull(parentType.FindNavigation("Child").TargetEntityType)
+
+ Dim table = o.GetRelationalModel().Tables.Single()
+ Assert.Equal({"Id", "Child_Name", "Name"}, table.Columns.Select(Function(t) t.Name))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_column_name_on_specific_table_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of DerivedEntity)().HasBaseType(Of BaseEntity)()
+ builder.Entity(Of DuplicateDerivedEntity)().HasBaseType(Of BaseEntity)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(3, o.GetEntityTypes().Count())
+ Assert.Collection(
+ o.GetEntityTypes(),
+ Sub(t)
+ Assert.Equal("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+BaseEntity", t.Name)
+ End Sub,
+ Sub(t)
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+DerivedEntity", t.Name)
+ End Sub,
+ Sub(t)
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+DuplicateDerivedEntity", t.Name)
+ Assert.Equal(
+ "DuplicateDerivedEntity_Name",
+ t.FindProperty(NameOf(DuplicateDerivedEntity.Name)).
+ GetColumnName(StoreObjectIdentifier.Table(NameOf(BaseEntity), "DefaultSchema")))
+ End Sub)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_column_type_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasColumnType("CType")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("CType", o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:ColumnType"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_default_value_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasDefaultValue(1)
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(1, o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:DefaultValue"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_default_value_annotation_is_stored_in_snapshot_as_fluent_api_unspecified()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasDefaultValue()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsSystem:=True),
+ Sub(o)
+ Assert.Equal(DBNull.Value, o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:DefaultValue"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_default_value_sql_annotation_is_stored_in_snapshot_as_fluent_api_unspecified()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasDefaultValueSql()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(String.Empty, o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:DefaultValueSql"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_default_value_sql_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasDefaultValueSql("SQL")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("SQL", o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:DefaultValueSql"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_computed_column_sql_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasComputedColumnSql("SQL")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("SQL", o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:ComputedColumnSql"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_computed_column_sql_stored_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasComputedColumnSql("SQL", True)
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("SQL", o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:ComputedColumnSql"))
+ Assert.Equal(True, o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:IsStored"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_computed_column_sql_annotation_is_stored_in_snapshot_as_fluent_api_unspecified()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasComputedColumnSql()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(String.Empty, o.GetEntityTypes().First().FindProperty("AlternateId")("Relational:ComputedColumnSql"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_default_value_of_enum_type_is_stored_in_snapshot_without_actual_enum()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithEnumType)().Property(Function(e) e.Day).HasDefaultValue(Days.Wed)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(3L, o.GetEntityTypes().First().FindProperty("Day")("Relational:DefaultValue"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_enum_type_is_stored_in_snapshot_with_custom_conversion_and_seed_data()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithEnumType)(
+ Sub(eb)
+ eb.Property(Function(e) e.Day).HasDefaultValue(Days.Wed).
+ HasConversion(Function(v) v.ToString(), Function(v) CType([Enum].Parse(GetType(Days), v), Days))
+ eb.HasData(New EntityWithEnumType With {.Id = 1, .Day = Days.Fri})
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.GetEntityTypes().First().FindProperty("Day")
+ Assert.Equal(GetType(String), [property].ClrType)
+ Assert.Equal(NameOf(Days.Wed), [property]("Relational:DefaultValue"))
+ Assert.False([property].IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_of_nullable_enum()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithNullableEnumType)().Property(Function(e) e.Day).
+ HasConversion(Function(d) d, Function(d) d)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().First().FindProperty("Day").IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_of_enum_to_nullable()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithEnumType)().Property(Function(e) e.Day).
+ HasConversion(Function(m) CType(m, Long?), Function(p) If(p.HasValue, CType(p.Value, Days), Nothing))
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.False(o.GetEntityTypes().First().FindProperty("Day").IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_of_nullable_enum_to_string()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithNullableEnumType)().Property(Function(e) e.Day).HasConversion(Of String)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().First().FindProperty("Day").IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_multiple_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasColumnName("CName").
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.GetEntityTypes().First().FindProperty("AlternateId")
+ Assert.Equal(3, [property].GetAnnotations().Count())
+ Assert.Equal("AnnotationValue", [property]("AnnotationName"))
+ Assert.Equal("CName", [property]("Relational:ColumnName"))
+ Assert.Equal("int", [property]("Relational:ColumnType"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_without_column_type()
+ Test(
+ Sub(builder)
+ builder.
+ HasAnnotation(SqlServerAnnotationNames.ValueGenerationStrategy, SqlServerValueGenerationStrategy.IdentityColumn)
+
+ builder.Entity(
+ "Building",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasAnnotation(
+ SqlServerAnnotationNames.ValueGenerationStrategy, SqlServerValueGenerationStrategy.IdentityColumn)
+
+ b.HasKey("Id")
+
+ b.ToTable("Buildings", "DefaultSchema")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.FindEntityType("Building").FindProperty("Id")
+ Assert.Equal("int", [property].GetColumnType())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_with_identity_column()
+ Test(
+ Sub(builder)
+ builder.Entity(
+ "Building",
+ Sub(b)
+ b.Property(Of Integer)("Id").UseIdentityColumn()
+
+ b.HasKey("Id")
+
+ b.ToTable("Buildings", "DefaultSchema")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.FindEntityType("Building").FindProperty("Id")
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, [property].GetValueGenerationStrategy())
+ Assert.Equal(1, [property].GetIdentitySeed())
+ Assert.Equal(1, [property].GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_with_identity_column_custom_seed()
+ Test(
+ Sub(builder)
+ builder.Entity(
+ "Building",
+ Sub(b)
+ b.Property(Of Integer)("Id").UseIdentityColumn(seed:=5)
+
+ b.HasKey("Id")
+
+ b.ToTable("Buildings", "DefaultSchema")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.FindEntityType("Building").FindProperty("Id")
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, [property].GetValueGenerationStrategy())
+ Assert.Equal(5, [property].GetIdentitySeed())
+ Assert.Equal(1, [property].GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_with_identity_column_custom_increment()
+ Test(
+ Sub(builder)
+ builder.Entity(
+ "Building",
+ Sub(b)
+ b.Property(Of Integer)("Id").UseIdentityColumn(increment:=5)
+
+ b.HasKey("Id")
+
+ b.ToTable("Buildings", "DefaultSchema")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.FindEntityType("Building").FindProperty("Id")
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, [property].GetValueGenerationStrategy())
+ Assert.Equal(1, [property].GetIdentitySeed())
+ Assert.Equal(5, [property].GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_with_identity_column_custom_seed_increment()
+ Test(
+ Sub(builder)
+ builder.Entity(
+ "Building",
+ Sub(b)
+ b.Property(Of Integer)("Id").UseIdentityColumn(5, 5)
+
+ b.HasKey("Id")
+
+ b.ToTable("Buildings", "DefaultSchema")
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.FindEntityType("Building").FindProperty("Id")
+ Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, [property].GetValueGenerationStrategy())
+ Assert.Equal(5, [property].GetIdentitySeed())
+ Assert.Equal(5, [property].GetIdentityIncrement())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Property_column_order_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Of Integer)("AlternateId").HasColumnOrder(1)
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(1, o.GetEntityTypes().First().FindProperty("AlternateId").GetColumnOrder())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub SQLServer_model_legacy_identity_seed_int_annotation()
+ Test(
+ Sub(builder)
+ builder.HasAnnotation(SqlServerAnnotationNames.IdentitySeed, 8)
+ End Sub,
+ AddBoilerPlate(
+ .Value),
+ Sub(o)
+ Assert.Equal(8L, o.GetIdentitySeed())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub SQLServer_property_legacy_identity_seed_int_annotation()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().Property(Function(e) e.Id).
+ HasAnnotation(SqlServerAnnotationNames.IdentitySeed, 8)
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(8L, o.GetEntityTypes().First().FindProperty("Id").GetIdentitySeed())
+ End Sub)
+ End Sub
+#End Region
+
+#Region "Primitive collection"
+
+ Public Overridable Sub PrimitiveCollection_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty).
+ PrimitiveCollection(Of List(Of Integer))("List").
+ IsSparse().
+ IsFixedLength().
+ HasMaxLength(100).
+ IsUnicode().
+ UseCollation("ListCollation").
+ HasSentinel(New List(Of Integer)).
+ HasColumnName("ListColumn").
+ HasColumnType("nvarchar").
+ HasColumnOrder(1).
+ HasComment("ListComment").
+ HasComputedColumnSql("ListSql").
+ HasJsonPropertyName("ListJson").
+ ElementType(Function(b) b.HasConversion(Of String)).
+ ValueGeneratedOnUpdateSometimes().
+ HasAnnotation("AnnotationName", "AnnotationValue")
+
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim [property] = o.GetEntityTypes().First().FindProperty("List")
+ Assert.Equal("AnnotationValue", [property]("AnnotationName"))
+ End Sub)
+ End Sub
+#End Region
+
+#Region "Complex types"
+
+
+ Public Overridable Sub Complex_properties_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)(
+ Sub(b)
+ b.ComplexProperty(
+ Function(eo) eo.EntityWithTwoProperties,
+ Sub(eb)
+ eb.IsRequired()
+ eb.Property(Function(e) e.AlternateId).HasColumnOrder(1).IsSparse()
+ eb.PrimitiveCollection(Of List(Of String))("List").
+ HasColumnType("nvarchar(max)").
+ IsSparse()
+ eb.ComplexProperty(Function(e) e.EntityWithStringKey).
+ IsRequired().
+ Ignore(Function(e) e.Properties)
+ eb.HasPropertyAnnotation("PropertyAnnotation", 1)
+ eb.HasTypeAnnotation("TypeAnnotation", 2)
+ End Sub)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value, importsCollections:=True),
+ Sub(z, o)
+ Dim anEntityWithOneProperty = o.FindEntityType(GetType(EntityWithOneProperty))
+ Assert.Equal(NameOf(EntityWithOneProperty), anEntityWithOneProperty.GetTableName())
+
+ Dim complexProperty = anEntityWithOneProperty.FindComplexProperty(NameOf(EntityWithOneProperty.EntityWithTwoProperties))
+ Assert.False(complexProperty.IsCollection)
+ Assert.False(complexProperty.IsNullable)
+ Dim complexType = complexProperty.ComplexType
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties",
+ complexType.Name)
+ Assert.Equal("EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties", complexType.DisplayName())
+ Assert.Equal(NameOf(EntityWithOneProperty), complexType.GetTableName())
+ Dim alternateIdProperty = complexType.FindProperty(NameOf(EntityWithTwoProperties.AlternateId))
+ Assert.Equal(1, alternateIdProperty.GetColumnOrder())
+ Assert.Equal(1, complexProperty("PropertyAnnotation"))
+ Assert.Equal(2, complexProperty.ComplexType("TypeAnnotation"))
+
+ Dim nestedComplexProperty = complexType.FindComplexProperty(NameOf(EntityWithTwoProperties.EntityWithStringKey))
+ Assert.False(nestedComplexProperty.IsCollection)
+ Assert.False(nestedComplexProperty.IsNullable)
+ Dim nestedComplexType = nestedComplexProperty.ComplexType
+ Assert.Equal(
+ "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties.EntityWithStringKey#EntityWithStringKey",
+ nestedComplexType.Name)
+ Assert.Equal(
+ "EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties.EntityWithStringKey#EntityWithStringKey",
+ nestedComplexType.DisplayName())
+ Assert.Equal(NameOf(EntityWithOneProperty), nestedComplexType.GetTableName())
+ Dim nestedIdProperty = nestedComplexType.FindProperty(NameOf(EntityWithStringKey.Id))
+ Assert.True(nestedIdProperty.IsNullable)
+ End Sub,
+ validate:=True)
+ End Sub
+#End Region
+
+#Region "HasKey"
+
+ Public Overridable Sub Key_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasAlternateKey(Function(t) t.AlternateId).
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "AnnotationValue", o.GetEntityTypes().First().GetKeys().Where(Function(k) Not k.IsPrimaryKey()).First()("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Key_Fluent_APIs_are_properly_generated()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().HasKey(Function(t) t.Id).IsClustered()
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().First().GetKeys().Single(Function(k) k.IsPrimaryKey()).IsClustered())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Key_name_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasAlternateKey(Function(t) t.AlternateId).HasName("KeyName")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "KeyName", o.GetEntityTypes().First().GetKeys().Where(Function(k) Not k.IsPrimaryKey()).First()("Relational:Name"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Key_multiple_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasAlternateKey(Function(t) t.AlternateId).HasName("IndexName").
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim key = o.GetEntityTypes().First().GetKeys().Where(Function(k) Not k.IsPrimaryKey()).First()
+ Assert.Equal(2, key.GetAnnotations().Count())
+ Assert.Equal("AnnotationValue", key("AnnotationName"))
+ Assert.Equal("IndexName", key("Relational:Name"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Key_fill_factor_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().HasKey(Function(t) t.Id).HasFillFactor(90)
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(90, o.GetEntityTypes().First().GetKeys().Single(Function(k) k.IsPrimaryKey()).GetFillFactor())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Unique_constraint_fill_factor_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasAlternateKey(Function(t) t.AlternateId).HasName("KeyName").HasFillFactor(90)
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim key = model.GetEntityTypes().First().GetKeys().First()
+ Assert.Equal(90, key.GetFillFactor())
+ End Sub)
+ End Sub
+#End Region
+
+#Region "Index"
+
+ Public Overridable Sub Index_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(Function(t) t.AlternateId).
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal("AnnotationValue", o.GetEntityTypes().First().GetIndexes().First()("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_Fluent_APIs_are_properly_generated()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(Function(t) t.AlternateId).IsClustered()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().Single().GetIndexes().Single().IsClustered())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_IsUnique_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(Function(t) t.AlternateId).IsUnique()
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.GetEntityTypes().First().GetIndexes().First().IsUnique)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_IsDescending_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithThreeProperties)(
+ Sub(e)
+ e.HasIndex(
+ Function(t) New With {
+ t.X,
+ t.Y,
+ t.Z
+ }, "IX_unspecified")
+ e.HasIndex(
+ Function(t) New With {
+ t.X,
+ t.Y,
+ t.Z
+ }, "IX_empty").
+ IsDescending()
+ e.HasIndex(
+ Function(t) New With {
+ t.X,
+ t.Y,
+ t.Z
+ }, "IX_all_ascending").
+ IsDescending(False, False, False)
+ e.HasIndex(
+ Function(t) New With {
+ t.X,
+ t.Y,
+ t.Z
+ }, "IX_all_descending").
+ IsDescending(True, True, True)
+ e.HasIndex(
+ Function(t) New With {
+ t.X,
+ t.Y,
+ t.Z
+ }, "IX_mixed").
+ IsDescending(False, True, False)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim entityType = o.GetEntityTypes().Single()
+ Assert.Equal(5, entityType.GetIndexes().Count())
+
+ Dim unspecifiedIndex = Assert.Single(entityType.GetIndexes(), Function(i) i.Name = "IX_unspecified")
+ Assert.Null(unspecifiedIndex.IsDescending)
+
+ Dim emptyIndex = Assert.Single(entityType.GetIndexes(), Function(i) i.Name = "IX_empty")
+ Assert.Equal(Array.Empty(Of Boolean), emptyIndex.IsDescending)
+
+ Dim allAscendingIndex = Assert.Single(entityType.GetIndexes(), Function(i) i.Name = "IX_all_ascending")
+ Assert.Null(allAscendingIndex.IsDescending)
+
+ Dim allDescendingIndex = Assert.Single(entityType.GetIndexes(), Function(i) i.Name = "IX_all_descending")
+ Assert.Equal(Array.Empty(Of Boolean), allDescendingIndex.IsDescending)
+
+ Dim mixedIndex = Assert.Single(entityType.GetIndexes(), Function(i) i.Name = "IX_mixed")
+ Assert.Equal({False, True, False}, mixedIndex.IsDescending)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_database_name_annotation_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().
+ HasIndex(Function(t) t.AlternateId).
+ HasDatabaseName("IndexName")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim index = o.GetEntityTypes().First().GetIndexes().First()
+ Assert.Null(index.Name)
+ Assert.Equal("IndexName", index.GetDatabaseName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_filter_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(Function(t) t.AlternateId).
+ HasFilter("AlternateId (Of ) 0")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "AlternateId (Of ) 0",
+ o.GetEntityTypes().First().GetIndexes().First().GetFilter())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_multiple_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().HasIndex(Function(t) t.AlternateId, "IndexName").
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ builder.Ignore(Of EntityWithOneProperty)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim index = o.GetEntityTypes().First().GetIndexes().First()
+ Assert.Equal("IndexName", index.Name)
+ Assert.Single(index.GetAnnotations())
+ Assert.Equal("AnnotationValue", index("AnnotationName"))
+ Assert.Null(index("RelationalAnnotationNames.Name"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Index_with_default_constraint_name_exceeding_max()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)(
+ Sub(x)
+ Const propertyName As String =
+ "SomePropertyWithAnExceedinglyLongIdentifierThatCausesTheDefaultIndexNameToExceedTheMaximumIdentifierLimit"
+ x.Property(Of String)(propertyName)
+ x.HasIndex(propertyName)
+ End Sub)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(128, o.GetEntityTypes().First().GetIndexes().First().GetDatabaseName().Length)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_causes_column_to_have_key_or_index_column_length()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithIndexAttribute)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Assert.Collection(
+ model.GetEntityTypes().First().GetIndexes().First().Properties,
+ Sub(p0)
+ Assert.Equal("FirstName", p0.Name)
+ Assert.Equal("nvarchar(450)", p0.GetColumnType())
+ End Sub,
+ Sub(p1)
+ Assert.Equal("LastName", p1.Name)
+ Assert.Equal("nvarchar(450)", p1.GetColumnType())
+ End Sub)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_name_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithNamedIndexAttribute)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim index = model.GetEntityTypes().First().GetIndexes().First()
+ Assert.Equal("NamedIndex", index.Name)
+ Assert.Collection(
+ index.Properties,
+ Sub(p0)
+ Assert.Equal("FirstName", p0.Name)
+ Assert.Equal("nvarchar(450)", p0.GetColumnType())
+ End Sub,
+ Sub(p1)
+ Assert.Equal("LastName", p1.Name)
+ Assert.Equal("nvarchar(450)", p1.GetColumnType())
+ End Sub)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_IsUnique_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithUniqueIndexAttribute)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim index = model.GetEntityTypes().First().GetIndexes().First()
+ Assert.True(index.IsUnique)
+ Assert.Collection(
+ index.Properties,
+ Sub(p0)
+ Assert.Equal("FirstName", p0.Name)
+ Assert.Equal("nvarchar(450)", p0.GetColumnType())
+ End Sub,
+ Sub(p1)
+ Assert.Equal("LastName", p1.Name)
+ Assert.Equal("nvarchar(450)", p1.GetColumnType())
+ End Sub)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_IncludeProperties_generated_without_fluent_api()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithStringProperty)(
+ Sub(x)
+ x.HasIndex(Function(e) e.Id).IncludeProperties(Function(e) e.Name)
+ End Sub),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim index = model.GetEntityTypes().First().GetIndexes().First()
+ Assert.Equal("Name", Assert.Single(index.GetIncludeProperties()))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_HasFillFactor_is_stored_in_snapshot()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithStringProperty)(
+ Sub(x)
+ x.HasIndex(Function(e) e.Id).HasFillFactor(29)
+ End Sub),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim index = model.GetEntityTypes().First().GetIndexes().First()
+ Assert.Equal(29, index.GetFillFactor())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_UseDataCompression_is_stored_in_snapshot()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithStringProperty)(
+ Sub(x)
+ x.HasIndex(Function(e) e.Id).UseDataCompression(DataCompressionType.Row)
+ End Sub),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim index = model.GetEntityTypes().First().GetIndexes().First()
+ Assert.Equal(DataCompressionType.Row, index.GetDataCompression())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub IndexAttribute_SortInTempDb_is_stored_in_snapshot()
+ Test(
+ Sub(builder) builder.Entity(Of EntityWithStringProperty)(
+ Sub(x)
+ x.HasIndex(Function(e) e.Id).SortInTempDb()
+ End Sub),
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(model)
+ Dim index = model.GetEntityTypes().First().GetIndexes().First()
+ Assert.True(index.GetSortInTempDb())
+ End Sub)
+ End Sub
+#End Region
+
+#Region "ForeignKey"
+
+ Public Overridable Sub ForeignKey_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().
+ HasOne(Function(e) e.EntityWithOneProperty).
+ WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId).
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "AnnotationValue", o.FindEntityType(GetType(EntityWithTwoProperties)).GetForeignKeys().First()("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_isRequired_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringKey)().Ignore(Function(e) e.Properties)
+ builder.Entity(Of EntityWithStringProperty)().
+ HasOne(Of EntityWithStringKey)().
+ WithOne().
+ HasForeignKey(Of EntityWithStringProperty)(Function(e) e.Name).
+ IsRequired()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.False(o.FindEntityType(GetType(EntityWithStringProperty)).FindProperty("Name").IsNullable)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_isUnique_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().
+ HasOne(Of EntityWithStringKey)().
+ WithMany(Function(e) e.Properties).
+ HasForeignKey(Function(e) e.Name)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.False(o.FindEntityType(GetType(EntityWithStringProperty)).GetForeignKeys().First().IsUnique)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_with_non_primary_principal_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithStringProperty)().
+ HasOne(Of EntityWithStringAlternateKey)().
+ WithMany(Function(e) e.Properties).
+ HasForeignKey(Function(e) e.Name).
+ HasPrincipalKey(Function(e) e.AlternateId)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.False(o.FindEntityType(GetType(EntityWithStringProperty)).GetForeignKeys().First().IsUnique)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_deleteBehavior_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ HasOne(Function(e) e.EntityWithTwoProperties).
+ WithMany().
+ HasForeignKey(Function(e) e.Id)
+ builder.Entity(Of EntityWithTwoProperties)().Ignore(Function(e) e.EntityWithOneProperty)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ DeleteBehavior.Cascade, o.FindEntityType(GetType(EntityWithOneProperty)).GetForeignKeys().First().DeleteBehavior)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_deleteBehavior_is_stored_in_snapshot_for_one_to_one()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ HasOne(Function(e) e.EntityWithTwoProperties).
+ WithOne(Function(e) e.EntityWithOneProperty).
+ HasForeignKey(Of EntityWithOneProperty)(Function(e) e.Id)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ DeleteBehavior.Cascade, o.FindEntityType(GetType(EntityWithOneProperty)).GetForeignKeys().First().DeleteBehavior)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_name_preserved_when_generic()
+ Dim originalModel As IReadOnlyModel = Nothing
+
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithGenericKey(Of Guid))().HasMany(Of EntityWithGenericProperty(Of Guid))().WithOne().
+ HasForeignKey(Function(e) e.Property)
+
+ originalModel = builder.Model
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ ",
+ Sub(b)
+ b.Property(Of Guid)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("uniqueidentifier")
+
+ b.HasKey("Id")
+
+ b.ToTable("EntityWithGenericKey", "DefaultSchema")
+ End Sub)
+
+modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithGenericProperty",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.Property(Of Guid)("Property").
+ HasColumnType("uniqueidentifier")
+
+ b.HasKey("Id")
+
+ b.HasIndex("Property")
+
+ b.ToTable("EntityWithGenericProperty", "DefaultSchema")
+ End Sub)
+
+modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithGenericProperty",
+ Sub(b)
+ b.HasOne("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithGenericKey", Nothing).
+ WithMany().
+ HasForeignKey("Property").
+ OnDelete(DeleteBehavior.Cascade).
+ IsRequired()
+ End Sub)
+]]>.Value, importsSystem:=True),
+ Sub(model)
+ Dim originalParent = originalModel.FindEntityType(GetType(EntityWithGenericKey(Of Guid)))
+ Dim parent = model.FindEntityType(originalParent.Name)
+ Assert.NotNull(parent)
+
+ Dim originalChild = originalModel.FindEntityType(GetType(EntityWithGenericProperty(Of Guid)))
+ Dim child = model.FindEntityType(originalChild.Name)
+ Assert.NotNull(child)
+
+ Dim originalForeignKey = originalChild.FindForeignKey(
+ originalChild.FindProperty("Property"),
+ originalParent.FindPrimaryKey(),
+ originalParent)
+ Dim foreignKey = child.FindForeignKey(
+ child.FindProperty("Property"),
+ parent.FindPrimaryKey(),
+ parent)
+
+ Assert.Equal(originalForeignKey.GetConstraintName(), foreignKey.GetConstraintName())
+
+ Dim originalIndex = originalChild.FindIndex(originalChild.FindProperty("Property"))
+ Dim index = child.FindIndex(child.FindProperty("Property"))
+
+ Assert.Equal(originalIndex.GetDatabaseName(), index.GetDatabaseName())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_constraint_name_is_stored_in_snapshot_as_fluent_api()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().
+ HasOne(Function(e) e.EntityWithOneProperty).
+ WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId).
+ HasConstraintName("Constraint")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "Constraint", o.FindEntityType(GetType(EntityWithTwoProperties)).GetForeignKeys().First()("Relational:Name"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_multiple_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().
+ HasOne(Function(e) e.EntityWithOneProperty).
+ WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId).
+ HasAnnotation("AnnotationName", "AnnotationValue").
+ HasConstraintName("Constraint")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim fk = o.FindEntityType(GetType(EntityWithTwoProperties)).GetForeignKeys().First()
+ Assert.Equal(2, fk.GetAnnotations().Count())
+ Assert.Equal("AnnotationValue", fk("AnnotationName"))
+ Assert.Equal("Constraint", fk("Relational:Name"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Do_not_generate_entity_type_builder_again_if_no_foreign_key_is_defined_on_it()
+ Test(
+ Sub(builder)
+ builder.Entity(Of BaseType)()
+ builder.Ignore(Of EntityWithTwoProperties)()
+ builder.Entity(Of DerivedType)()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_principal_key_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ HasOne(Function(e) e.EntityWithTwoProperties).
+ WithOne(Function(e) e.EntityWithOneProperty).
+ HasForeignKey(Of EntityWithOneProperty)(Function(e) e.Id).
+ HasPrincipalKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId)
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(2, o.FindEntityType(GetType(EntityWithTwoProperties)).GetKeys().Count())
+ Assert.True(o.FindEntityType(GetType(EntityWithTwoProperties)).FindProperty("AlternateId").IsKey())
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub ForeignKey_principal_key_with_non_default_name_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithOneProperty)().
+ HasOne(Function(e) e.EntityWithTwoProperties).
+ WithOne(Function(e) e.EntityWithOneProperty).
+ HasForeignKey(Of EntityWithOneProperty)(Function(e) e.Id).
+ HasPrincipalKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId)
+
+ builder.Entity(Of EntityWithTwoProperties)().HasAlternateKey(Function(e) e.AlternateId).HasAnnotation("Name", "Value")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Dim entityType = o.FindEntityType(GetType(EntityWithTwoProperties))
+
+ Assert.Equal(2, entityType.GetKeys().Count())
+ Assert.Equal("Value", entityType.FindKey(entityType.FindProperty("AlternateId"))("Name"))
+ End Sub)
+ End Sub
+#End Region
+
+#Region "Navigation"
+
+ Public Overridable Sub Navigation_annotations_are_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().
+ HasOne(Function(e) e.EntityWithOneProperty).
+ WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId)
+
+ builder.Entity(Of EntityWithTwoProperties)().Navigation(Function(e) e.EntityWithOneProperty).
+ HasAnnotation("AnnotationName", "AnnotationValue")
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.Equal(
+ "AnnotationValue", o.FindEntityType(GetType(EntityWithTwoProperties)).GetNavigations().First()("AnnotationName"))
+ End Sub)
+ End Sub
+
+
+ Public Overridable Sub Navigation_isRequired_is_stored_in_snapshot()
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithTwoProperties)().
+ HasOne(Function(e) e.EntityWithOneProperty).
+ WithOne(Function(e) e.EntityWithTwoProperties).
+ HasForeignKey(Of EntityWithTwoProperties)(Function(e) e.AlternateId)
+
+ builder.Entity(Of EntityWithOneProperty)().Navigation(Function(e) e.EntityWithTwoProperties).
+ IsRequired()
+ End Sub,
+ AddBoilerPlate(
+ GetHeading() &
+ .Value),
+ Sub(o)
+ Assert.True(o.FindEntityType(GetType(EntityWithOneProperty)).GetNavigations().First().ForeignKey.IsRequiredDependent)
+ End Sub)
+ End Sub
+#End Region
+
+#Region "SeedData"
+ Private Shared Function getAllProperties(model As IModel) As List(Of IProperty)
+ Return model.
+ GetEntityTypes().
+ SelectMany(Function(m) m.GetProperties()).
+ OrderBy(Function(p) p.DeclaringType.Name).
+ ThenBy(Function(p) p.Name).
+ ToList()
+ End Function
+
+
+ Public Overridable Sub SeedData_annotations_are_stored_in_snapshot()
+ Dim lineString1 = New LineString(
+ {New Coordinate(1.1, 2.2), New Coordinate(2.2, 2.2), New Coordinate(2.2, 1.1), New Coordinate(7.1, 7.2)}) With {.SRID = 4326}
+
+ Dim lineString2 = New LineString(
+ {New Coordinate(7.1, 7.2), New Coordinate(20.2, 20.2), New Coordinate(20.2, 1.1), New Coordinate(70.1, 70.2)}) With {.SRID = 4326}
+
+ Dim multiPoint = New MultiPoint(
+ {New Point(1.1, 2.2), New Point(2.2, 2.2), New Point(2.2, 1.1)}) With {.SRID = 4326}
+
+ Dim polygon1 = New Polygon(
+ New LinearRing(
+ {New Coordinate(1.1, 2.2), New Coordinate(2.2, 2.2), New Coordinate(2.2, 1.1), New Coordinate(1.1, 2.2)})) With {.SRID = 4326}
+
+ Dim polygon2 = New Polygon(
+ New LinearRing(
+ {New Coordinate(10.1, 20.2), New Coordinate(20.2, 20.2), New Coordinate(20.2, 10.1), New Coordinate(10.1, 20.2)})) With {.SRID = 4326}
+
+ Dim point1 = New Point(1.1, 2.2, 3.3) With {.SRID = 4326}
+
+ Dim multiLineString = New MultiLineString({lineString1, lineString2}) With {.SRID = 4326}
+
+ Dim multiPolygon = New MultiPolygon({polygon2, polygon1}) With {.SRID = 4326}
+
+ Dim geometryCollection = New GeometryCollection(
+ {lineString1, lineString2, multiPoint, polygon1, polygon2, point1, multiLineString, multiPolygon}) With {.SRID = 4326}
+
+ Test(
+ Sub(builder)
+ builder.Entity(Of EntityWithManyProperties)(
+ Sub(eb)
+ eb.Property(Of Decimal?)("OptionalProperty")
+
+ eb.HasData(
+ New With {
+ .Id = 42,
+ .String = "FortyThree",
+ .Bytes = New Byte() {44, 45},
+ .Int16 = 46S,
+ .Int32 = 47,
+ .Int64 = 48L,
+ .Double = 49.0,
+ .Decimal = 50D,
+ .DateTime = New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc),
+ .DateTimeOffset = New DateTimeOffset(New DateTime(1973, 9, 3, 12, 10, 42, 344), New TimeSpan(1, 0, 0)),
+ .TimeSpan = New TimeSpan(51, 52, 53),
+ .Single = 54.0F,
+ .Boolean = True,
+ .Byte = CByte(55),
+ .UnsignedInt16 = 56US,
+ .UnsignedInt32 = 57UI,
+ .UnsignedInt64 = 58UL,
+ .Character = "9"c,
+ .SignedByte = CSByte(60),
+ .Enum64 = Enum64.SomeValue,
+ .Enum32 = Enum32.SomeValue,
+ .Enum16 = Enum16.SomeValue,
+ .Enum8 = Enum8.SomeValue,
+ .EnumU64 = EnumU64.SomeValue,
+ .EnumU32 = EnumU32.SomeValue,
+ .EnumU16 = EnumU16.SomeValue,
+ .EnumS8 = EnumS8.SomeValue,
+ .SpatialBGeometryCollection = geometryCollection,
+ .SpatialBLineString = lineString1,
+ .SpatialBMultiLineString = multiLineString,
+ .SpatialBMultiPoint = multiPoint,
+ .SpatialBMultiPolygon = multiPolygon,
+ .SpatialBPoint = point1,
+ .SpatialBPolygon = polygon1,
+ .SpatialCGeometryCollection = geometryCollection,
+ .SpatialCLineString = lineString1,
+ .SpatialCMultiLineString = multiLineString,
+ .SpatialCMultiPoint = multiPoint,
+ .SpatialCMultiPolygon = multiPolygon,
+ .SpatialCPoint = point1,
+ .SpatialCPolygon = polygon1,
+ .Int32Collection = {1, 2, 3, 4},
+ .DoubleCollection = {1.2, 3.4},
+ .StringCollection = {"AB", "CD"},
+ .DateTimeCollection = {New Date(2023, 9, 7), New Date(2023, 11, 14)},
+ .BoolCollection = {True, False},
+ .BytesCollection = {New Byte() {1, 2}, New Byte() {3, 4}}},
+ New With {
+ .Id = 43,
+ .String = "FortyThree",
+ .Bytes = New Byte() {44, 45},
+ .Int16 = -46S,
+ .Int32 = -47,
+ .Int64 = -48L,
+ .Double = -49.0,
+ .Decimal = -50D,
+ .DateTime = New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc),
+ .DateTimeOffset = New DateTimeOffset(New DateTime(1973, 9, 3, 12, 10, 42, 344), New TimeSpan(-1, 0, 0)),
+ .TimeSpan = New TimeSpan(-51, 52, 53),
+ .Single = -54.0F,
+ .Boolean = True,
+ .Byte = CByte(55),
+ .UnsignedInt16 = 56US,
+ .UnsignedInt32 = 57UI,
+ .UnsignedInt64 = 58UL,
+ .Character = "9"c,
+ .SignedByte = CSByte(-60),
+ .Enum64 = Enum64.SomeValue,
+ .Enum32 = Enum32.SomeValue,
+ .Enum16 = Enum16.SomeValue,
+ .Enum8 = Enum8.SomeValue,
+ .EnumU64 = EnumU64.SomeValue,
+ .EnumU32 = EnumU32.SomeValue,
+ .EnumU16 = EnumU16.SomeValue,
+ .EnumS8 = EnumS8.SomeValue})
+ End Sub)
+ builder.Ignore(Of EntityWithTwoProperties)()
+ End Sub,
+
+Imports System
+Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+Imports NetTopologySuite.Geometries
+
+Namespace Global.RootNamespace
+
+ Partial Class Snapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
+ modelBuilder.
+ HasDefaultSchema("DefaultSchema").
+ HasAnnotation("Relational:MaxIdentifierLength", 128)
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
+
+ modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithManyProperties",
+ Sub(b)
+ b.Property(Of Integer)("Id").
+ ValueGeneratedOnAdd().
+ HasColumnType("int")
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property(Of Integer)("Id"))
+
+ b.PrimitiveCollection(Of String)("BoolCollection").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of Boolean)("Boolean").
+ HasColumnType("bit")
+
+ b.Property(Of Byte)("Byte").
+ HasColumnType("tinyint")
+
+ b.Property(Of Byte())("Bytes").
+ HasColumnType("varbinary(max)")
+
+ b.PrimitiveCollection(Of String)("BytesCollection").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of String)("Character").
+ IsRequired().
+ HasColumnType("nvarchar(1)")
+
+ b.Property(Of Date)("DateTime").
+ HasColumnType("datetime2")
+
+ b.PrimitiveCollection(Of String)("DateTimeCollection").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of DateTimeOffset)("DateTimeOffset").
+ HasColumnType("datetimeoffset")
+
+ b.Property(Of Decimal)("Decimal").
+ HasColumnType("decimal(18,2)")
+
+ b.Property(Of Double)("Double").
+ HasColumnType("float")
+
+ b.PrimitiveCollection(Of String)("DoubleCollection").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of Short)("Enum16").
+ HasColumnType("smallint")
+
+ b.Property(Of Integer)("Enum32").
+ HasColumnType("int")
+
+ b.Property(Of Long)("Enum64").
+ HasColumnType("bigint")
+
+ b.Property(Of Byte)("Enum8").
+ HasColumnType("tinyint")
+
+ b.Property(Of Short)("EnumS8").
+ HasColumnType("smallint")
+
+ b.Property(Of Integer)("EnumU16").
+ HasColumnType("int")
+
+ b.Property(Of Long)("EnumU32").
+ HasColumnType("bigint")
+
+ b.Property(Of Decimal)("EnumU64").
+ HasColumnType("decimal(20,0)")
+
+ b.Property(Of Short)("Int16").
+ HasColumnType("smallint")
+
+ b.Property(Of Integer)("Int32").
+ HasColumnType("int")
+
+ b.PrimitiveCollection(Of String)("Int32Collection").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of Long)("Int64").
+ HasColumnType("bigint")
+
+ b.Property(Of Decimal?)("OptionalProperty").
+ HasColumnType("decimal(18,2)")
+
+ b.Property(Of Short)("SignedByte").
+ HasColumnType("smallint")
+
+ b.Property(Of Single)("Single").
+ HasColumnType("real")
+
+ b.Property(Of Geometry)("SpatialBGeometryCollection").
+ HasColumnType("geography")
+
+ b.Property(Of Geometry)("SpatialBLineString").
+ HasColumnType("geography")
+
+ b.Property(Of Geometry)("SpatialBMultiLineString").
+ HasColumnType("geography")
+
+ b.Property(Of Geometry)("SpatialBMultiPoint").
+ HasColumnType("geography")
+
+ b.Property(Of Geometry)("SpatialBMultiPolygon").
+ HasColumnType("geography")
+
+ b.Property(Of Geometry)("SpatialBPoint").
+ HasColumnType("geography")
+
+ b.Property(Of Geometry)("SpatialBPolygon").
+ HasColumnType("geography")
+
+ b.Property(Of GeometryCollection)("SpatialCGeometryCollection").
+ HasColumnType("geography")
+
+ b.Property(Of LineString)("SpatialCLineString").
+ HasColumnType("geography")
+
+ b.Property(Of MultiLineString)("SpatialCMultiLineString").
+ HasColumnType("geography")
+
+ b.Property(Of MultiPoint)("SpatialCMultiPoint").
+ HasColumnType("geography")
+
+ b.Property(Of MultiPolygon)("SpatialCMultiPolygon").
+ HasColumnType("geography")
+
+ b.Property(Of Point)("SpatialCPoint").
+ HasColumnType("geography")
+
+ b.Property(Of Polygon)("SpatialCPolygon").
+ HasColumnType("geography")
+
+ b.Property(Of String)("String").
+ HasColumnType("nvarchar(max)")
+
+ b.PrimitiveCollection(Of String)("StringCollection").
+ HasColumnType("nvarchar(max)")
+
+ b.Property(Of TimeSpan)("TimeSpan").
+ HasColumnType("time")
+
+ b.Property(Of Integer)("UnsignedInt16").
+ HasColumnType("int")
+
+ b.Property(Of Long)("UnsignedInt32").
+ HasColumnType("bigint")
+
+ b.Property(Of Decimal)("UnsignedInt64").
+ HasColumnType("decimal(20,0)")
+
+ b.HasKey("Id")
+
+ b.ToTable("EntityWithManyProperties", "DefaultSchema")
+
+ b.HasData({
+ New With {
+ .Id = 42,
+ .BoolCollection = "[true,false]",
+ .[Boolean] = True,
+ .[Byte] = CByte(55),
+ .Bytes = New Byte() {44, 45},
+ .BytesCollection = "[""AQI="",""AwQ=""]",
+ .Character = "9",
+ .DateTime = New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc),
+ .DateTimeCollection = "[""2023-09-07T00:00:00"",""2023-11-14T00:00:00""]",
+ .DateTimeOffset = New DateTimeOffset(New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Unspecified), New TimeSpan(0, 1, 0, 0, 0)),
+ .[Decimal] = 50D,
+ .[Double] = 49.0,
+ .DoubleCollection = "[1.2,3.4]",
+ .Enum16 = 1S,
+ .Enum32 = 1,
+ .Enum64 = 1L,
+ .Enum8 = CByte(1),
+ .EnumS8 = -128S,
+ .EnumU16 = 65535,
+ .EnumU32 = 4294967295L,
+ .EnumU64 = 1234567890123456789D,
+ .Int16 = 46S,
+ .Int32 = 47,
+ .Int32Collection = "[1,2,3,4]",
+ .Int64 = 48L,
+ .SignedByte = 60S,
+ .[Single] = 54F,
+ .SpatialBGeometryCollection = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))"), NetTopologySuite.Geometries.GeometryCollection),
+ .SpatialBLineString = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)"), NetTopologySuite.Geometries.LineString),
+ .SpatialBMultiLineString = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))"), NetTopologySuite.Geometries.MultiLineString),
+ .SpatialBMultiPoint = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))"), NetTopologySuite.Geometries.MultiPoint),
+ .SpatialBMultiPolygon = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))"), NetTopologySuite.Geometries.MultiPolygon),
+ .SpatialBPoint = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;POINT Z(1.1 2.2 3.3)"), NetTopologySuite.Geometries.Point),
+ .SpatialBPolygon = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))"), NetTopologySuite.Geometries.Polygon),
+ .SpatialCGeometryCollection = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;GEOMETRYCOLLECTION Z(LINESTRING Z(1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), LINESTRING Z(7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN), MULTIPOINT Z((1.1 2.2 NaN), (2.2 2.2 NaN), (2.2 1.1 NaN)), POLYGON Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN)), POLYGON Z((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), POINT Z(1.1 2.2 3.3), MULTILINESTRING Z((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 7.1 7.2 NaN), (7.1 7.2 NaN, 20.2 20.2 NaN, 20.2 1.1 NaN, 70.1 70.2 NaN)), MULTIPOLYGON Z(((10.1 20.2 NaN, 20.2 20.2 NaN, 20.2 10.1 NaN, 10.1 20.2 NaN)), ((1.1 2.2 NaN, 2.2 2.2 NaN, 2.2 1.1 NaN, 1.1 2.2 NaN))))"), NetTopologySuite.Geometries.GeometryCollection),
+ .SpatialCLineString = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;LINESTRING (1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2)"), NetTopologySuite.Geometries.LineString),
+ .SpatialCMultiLineString = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTILINESTRING ((1.1 2.2, 2.2 2.2, 2.2 1.1, 7.1 7.2), (7.1 7.2, 20.2 20.2, 20.2 1.1, 70.1 70.2))"), NetTopologySuite.Geometries.MultiLineString),
+ .SpatialCMultiPoint = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOINT ((1.1 2.2), (2.2 2.2), (2.2 1.1))"), NetTopologySuite.Geometries.MultiPoint),
+ .SpatialCMultiPolygon = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;MULTIPOLYGON (((10.1 20.2, 20.2 20.2, 20.2 10.1, 10.1 20.2)), ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2)))"), NetTopologySuite.Geometries.MultiPolygon),
+ .SpatialCPoint = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;POINT Z(1.1 2.2 3.3)"), NetTopologySuite.Geometries.Point),
+ .SpatialCPolygon = CType(New NetTopologySuite.IO.WKTReader().Read("SRID=4326;POLYGON ((1.1 2.2, 2.2 2.2, 2.2 1.1, 1.1 2.2))"), NetTopologySuite.Geometries.Polygon),
+ .[String] = "FortyThree",
+ .StringCollection = "[""AB"",""CD""]",
+ .TimeSpan = New TimeSpan(2, 3, 52, 53, 0),
+ .UnsignedInt16 = 56,
+ .UnsignedInt32 = 57L,
+ .UnsignedInt64 = 58D
+ },
+ New With {
+ .Id = 43,
+ .[Boolean] = True,
+ .[Byte] = CByte(55),
+ .Bytes = New Byte() {44, 45},
+ .Character = "9",
+ .DateTime = New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc),
+ .DateTimeOffset = New DateTimeOffset(New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Unspecified), New TimeSpan(0, -1, 0, 0, 0)),
+ .[Decimal] = -50D,
+ .[Double] = -49.0,
+ .Enum16 = 1S,
+ .Enum32 = 1,
+ .Enum64 = 1L,
+ .Enum8 = CByte(1),
+ .EnumS8 = -128S,
+ .EnumU16 = 65535,
+ .EnumU32 = 4294967295L,
+ .EnumU64 = 1234567890123456789D,
+ .Int16 = -46S,
+ .Int32 = -47,
+ .Int64 = -48L,
+ .SignedByte = -60S,
+ .[Single] = -54F,
+ .[String] = "FortyThree",
+ .TimeSpan = New TimeSpan(-2, -2, -7, -7, 0),
+ .UnsignedInt16 = 56,
+ .UnsignedInt32 = 57L,
+ .UnsignedInt64 = 58D
+ }
+ })
+ End Sub)
+ End Sub
+ End Class
+End Namespace
+]]>.Value,
+ Sub(snapshotModel, originalModel)
+ Dim originalProperties = getAllProperties(originalModel)
+ Dim snapshotProperties = getAllProperties(snapshotModel)
+
+ Assert.Equal(originalProperties.Count, snapshotProperties.Count)
+
+ For i = 0 To originalProperties.Count - 1
+ Dim originalProperty = originalProperties(i)
+ Dim snapshotProperty = snapshotProperties(i)
+
+ Assert.Equal(originalProperty.DeclaringType.Name, snapshotProperty.DeclaringType.Name)
+ Assert.Equal(originalProperty.Name, snapshotProperty.Name)
+
+ Assert.Equal(originalProperty.GetColumnType(), snapshotProperty.GetColumnType())
+ Assert.Equal(originalProperty.GetMaxLength(), snapshotProperty.GetMaxLength())
+ Assert.Equal(originalProperty.IsUnicode(), snapshotProperty.IsUnicode())
+ Assert.Equal(originalProperty.IsConcurrencyToken, snapshotProperty.IsConcurrencyToken)
+ Assert.Equal(originalProperty.IsFixedLength(), snapshotProperty.IsFixedLength())
+ Next
+
+ Assert.Collection(
+ snapshotModel.GetEntityTypes().SelectMany(Function(e) e.GetSeedData()),
+ Sub(seed)
+ Assert.Equal(42, seed("Id"))
+ Assert.Equal("FortyThree", seed("String"))
+ Assert.Equal(
+ New Byte() {44, 45}, seed("Bytes"))
+ Assert.Equal(CShort(46), seed("Int16"))
+ Assert.Equal(47, seed("Int32"))
+ Assert.Equal(CLng(48), seed("Int64"))
+ Assert.Equal(49.0, seed("Double"))
+ Assert.Equal(50D, seed("Decimal"))
+ Assert.Equal(New DateTime(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc), seed("DateTime"))
+ Assert.Equal(
+ New DateTimeOffset(New DateTime(1973, 9, 3, 12, 10, 42, 344), New TimeSpan(1, 0, 0)),
+ seed("DateTimeOffset"))
+ Assert.Equal(New TimeSpan(51, 52, 53), seed("TimeSpan"))
+ Assert.Equal(54.0F, seed("Single"))
+ Assert.Equal(True, seed("Boolean"))
+ Assert.Equal(CByte(55), seed("Byte"))
+ Assert.Equal(56, seed("UnsignedInt16"))
+ Assert.Equal(CLng(57), seed("UnsignedInt32"))
+ Assert.Equal(CDec(58), seed("UnsignedInt64"))
+ Assert.Equal("9", seed("Character"))
+ Assert.Equal(CShort(60), seed("SignedByte"))
+ Assert.Equal(1L, seed("Enum64"))
+ Assert.Equal(1, seed("Enum32"))
+ Assert.Equal(CShort(1), seed("Enum16"))
+ Assert.Equal(CByte(1), seed("Enum8"))
+ Assert.Equal(1234567890123456789D, seed("EnumU64"))
+ Assert.Equal(4294967295L, seed("EnumU32"))
+ Assert.Equal(65535, seed("EnumU16"))
+ Assert.Equal(CShort(-128), seed("EnumS8"))
+ Assert.Equal(geometryCollection, seed("SpatialBGeometryCollection"))
+ Assert.Equal(lineString1, seed("SpatialBLineString"))
+ Assert.Equal(multiLineString, seed("SpatialBMultiLineString"))
+ Assert.Equal(multiPoint, seed("SpatialBMultiPoint"))
+ Assert.Equal(multiPolygon, seed("SpatialBMultiPolygon"))
+ Assert.Equal(point1, seed("SpatialBPoint"))
+ Assert.Equal(polygon1, seed("SpatialBPolygon"))
+ Assert.Equal(geometryCollection, seed("SpatialCGeometryCollection"))
+ Assert.Equal(lineString1, seed("SpatialCLineString"))
+ Assert.Equal(multiLineString, seed("SpatialCMultiLineString"))
+ Assert.Equal(multiPoint, seed("SpatialCMultiPoint"))
+ Assert.Equal(multiPolygon, seed("SpatialCMultiPolygon"))
+ Assert.Equal(point1, seed("SpatialCPoint"))
+ Assert.Equal(polygon1, seed("SpatialCPolygon"))
+
+ Assert.Equal(4326, CType(seed("SpatialBGeometryCollection"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialBLineString"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialBMultiLineString"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialBMultiPoint"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialBMultiPolygon"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialBPoint"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialBPolygon"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCGeometryCollection"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCLineString"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCMultiLineString"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCMultiPoint"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCMultiPolygon"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCPoint"), Geometry).SRID)
+ Assert.Equal(4326, CType(seed("SpatialCPolygon"), Geometry).SRID)
+
+ Assert.Equal("[1,2,3,4]", seed("Int32Collection"))
+ Assert.Equal("[1.2,3.4]", seed("DoubleCollection"))
+ Assert.Equal("[""AB"",""CD""]", seed("StringCollection"))
+ Assert.Equal("[""2023-09-07T00:00:00"",""2023-11-14T00:00:00""]", seed("DateTimeCollection"))
+ Assert.Equal("[true,false]", seed("BoolCollection"))
+ Assert.Equal("[""AQI="",""AwQ=""]", seed("BytesCollection"))
+ End Sub,
+ Sub(seed)
+ Assert.Equal(43, seed("Id"))
+ Assert.Equal("FortyThree", seed("String"))
+ Assert.Equal(
+ New Byte() {44, 45}, seed("Bytes"))
+ Assert.Equal(CShort(-46), seed("Int16"))
+ Assert.Equal(-47, seed("Int32"))
+ Assert.Equal(CLng(-48), seed("Int64"))
+ Assert.Equal(-49.0, seed("Double"))
+ Assert.Equal(-50D, seed("Decimal"))
+ Assert.Equal(New Date(1973, 9, 3, 12, 10, 42, 344, DateTimeKind.Utc), seed("DateTime"))
+ Assert.Equal(
+ New DateTimeOffset(New Date(1973, 9, 3, 12, 10, 42, 344), New TimeSpan(-1, 0, 0)),
+ seed("DateTimeOffset"))
+ Assert.Equal(New TimeSpan(-51, 52, 53), seed("TimeSpan"))
+ Assert.Equal(-54.0F, seed("Single"))
+ Assert.Equal(True, seed("Boolean"))
+ Assert.Equal(CByte(55), seed("Byte"))
+ Assert.Equal(56, seed("UnsignedInt16"))
+ Assert.Equal(CLng(57), seed("UnsignedInt32"))
+ Assert.Equal(CDec(58), seed("UnsignedInt64"))
+ Assert.Equal("9", seed("Character"))
+ Assert.Equal(CShort(-60), seed("SignedByte"))
+ Assert.Equal(1L, seed("Enum64"))
+ Assert.Equal(1, seed("Enum32"))
+ Assert.Equal(CShort(1), seed("Enum16"))
+ Assert.Equal(CByte(1), seed("Enum8"))
+ Assert.Equal(1234567890123456789D, seed("EnumU64"))
+ Assert.Equal(4294967295L, seed("EnumU32"))
+ Assert.Equal(65535, seed("EnumU16"))
+ Assert.Equal(CShort(-128), seed("EnumS8"))
+ End Sub)
+ End Sub)
+ End Sub
+#End Region
+
+ Protected Overridable Function GetHeading(Optional empty As Boolean = False) As String
+ Return .Value & If(empty, "", Environment.NewLine)
+ End Function
+
+ Protected Overridable Function GetReferences() As ICollection(Of BuildReference)
+ Return New List(Of BuildReference) From {
+ BuildReference.ByName("Microsoft.EntityFrameworkCore"),
+ BuildReference.ByName("Microsoft.EntityFrameworkCore.Abstractions"),
+ BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational"),
+ BuildReference.ByName("Microsoft.EntityFrameworkCore.SqlServer"),
+ BuildReference.ByName("NetTopologySuite"),
+ BuildReference.ByName(GetType(VisualBasicMigrationsGeneratorTests).Assembly.GetName().Name)}
+ End Function
+
+ Protected Overridable Function AddBoilerPlate(code As String, Optional importsSystem As Boolean = False, Optional importsCollections As Boolean = False) As String
+ Dim sb As New IndentedStringBuilder()
+ sb.AppendLine("' ")
+
+ If importsSystem Then
+ sb.AppendLine("Imports System")
+ End If
+
+ If importsCollections Then
+ sb.AppendLine("Imports System.Collections.Generic")
+ End If
+
+ sb.Append(
+"Imports Microsoft.EntityFrameworkCore
+Imports Microsoft.EntityFrameworkCore.Infrastructure
+Imports Microsoft.EntityFrameworkCore.Metadata
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
+Imports Microsoft.VisualBasic
+
+Namespace Global.RootNamespace
+
+ Partial Class Snapshot
+ Inherits ModelSnapshot
+
+ Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)")
+ sb.IncrementIndent().IncrementIndent().IncrementIndent().
+ AppendLine().
+ AppendLines(code).
+ DecrementIndent().DecrementIndent().DecrementIndent().
+ Append(
+" End Sub
+ End Class
+End Namespace
+")
+
+ Return sb.ToString()
+ End Function
+
+ Protected Sub Test(buildModel As Action(Of ModelBuilder), expectedCode As String, asserts As Action(Of IModel))
+ Test(buildModel, expectedCode, Sub(m As IModel, x As IModel) asserts(m))
+ End Sub
+
+ Protected Sub Test(buildModel As Action(Of ModelBuilder), expectedCode As String, asserts As Action(Of IModel, IModel), Optional validate As Boolean = False)
+ Dim modelBuilder = CreateConventionalModelBuilder()
+ modelBuilder.HasDefaultSchema("DefaultSchema")
+ modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.Snapshot)
+ modelBuilder.Model.RemoveAnnotation(CoreAnnotationNames.ProductVersion)
+ buildModel(modelBuilder)
+
+ Dim model = modelBuilder.FinalizeModel(designTime:=True, skipValidation:=Not validate)
+
+ Test(model, expectedCode, asserts)
+ End Sub
+
+ Protected Sub Test(model As IModel, expectedCode As String, asserts As Action(Of IModel, IModel))
+ Dim generator = CreateMigrationsGenerator()
+ Dim code = generator.GenerateSnapshot("RootNamespace", GetType(DbContext), "Snapshot", model)
+
+ Dim modelFromSnapshot = BuildModelFromSnapshotSource(code)
+ asserts(modelFromSnapshot, model)
+
+ Try
+ Assert.Equal(expectedCode, code, ignoreLineEndingDifferences:=True)
+ Catch e As EqualException
+ Throw New Exception(e.Message & Environment.NewLine & Environment.NewLine & "-- Actual code:" & Environment.NewLine & code)
+ End Try
+
+ Dim targetOptionsBuilder = TestHelpers.
+ AddProviderOptions(New DbContextOptionsBuilder()).
+ UseModel(model).
+ EnableSensitiveDataLogging()
+
+ Dim modelDiffer = CreateModelDiffer(targetOptionsBuilder.Options)
+
+ Dim noopOperations = modelDiffer.GetDifferences(modelFromSnapshot.GetRelationalModel(), model.GetRelationalModel())
+ Assert.Empty(noopOperations)
+ End Sub
+
+ Protected Function BuildModelFromSnapshotSource(code As String) As IModel
+ Dim build As New BuildSource With {
+ .Sources = New Dictionary(Of String, String) From {{"Snapshot.vb", code}}
+ }
+
+ For Each buildReference In GetReferences()
+ build.References.Add(buildReference)
+ Next
+
+ Dim assembly = build.BuildInMemory()
+ Dim snapshotType = assembly.GetType("RootNamespace.Snapshot")
+
+ Dim buildModelMethod = snapshotType.GetMethod(
+ "BuildModel",
+ BindingFlags.Instance Or BindingFlags.NonPublic,
+ Nothing,
+ {GetType(ModelBuilder)},
+ Nothing)
+
+ Dim builder = New ModelBuilder()
+ builder.Model.RemoveAnnotation(CoreAnnotationNames.ProductVersion)
+
+ buildModelMethod.Invoke(
+ Activator.CreateInstance(snapshotType),
+ {builder})
+
+ Dim services = TestHelpers.CreateContextServices(New ServiceCollection().AddEntityFrameworkSqlServerNetTopologySuite())
+
+ Dim processor = New SnapshotModelProcessor(New TestOperationReporter(), services.GetService(Of IModelRuntimeInitializer)())
+ Return processor.Process(builder.Model)
+ End Function
+
+ Protected Function CreateConventionalModelBuilder() As TestHelpers.TestModelBuilder
+ Return TestHelpers.CreateConventionBuilder(addServices:=AddressOf SqlServerNetTopologySuiteServiceCollectionExtensions.AddEntityFrameworkSqlServerNetTopologySuite)
+ End Function
+
+ Protected Overridable Function CreateModelDiffer(ByVal options As DbContextOptions) As MigrationsModelDiffer
+ Return CType(TestHelpers.CreateContext(options).GetService(Of IMigrationsModelDiffer)(), MigrationsModelDiffer)
+ End Function
+
+ Protected ReadOnly Property TestHelpers As TestHelpers
+ Get
+ Return SqlServerTestHelpers.Instance
+ End Get
+ End Property
+
+ Protected Function CreateMigrationsGenerator() As VisualBasicMigrationsGenerator
+
+ Dim sqlServerTypeMappingSource = New SqlServerTypeMappingSource(
+ TestServiceFactory.Instance.Create(Of TypeMappingSourceDependencies)(),
+ New RelationalTypeMappingSourceDependencies(
+ New IRelationalTypeMappingSourcePlugin() {
+ New SqlServerNetTopologySuiteTypeMappingSourcePlugin(NtsGeometryServices.Instance)
+ }))
+
+ Dim codeHelper = New VisualBasicHelper(sqlServerTypeMappingSource)
+
+ Dim sqlServerAnnotationCodeGenerator = New SqlServerAnnotationCodeGenerator(
+ New AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource))
+
+ Dim generator = New VisualBasicMigrationsGenerator(
+ New MigrationsCodeGeneratorDependencies(
+ sqlServerTypeMappingSource,
+ sqlServerAnnotationCodeGenerator),
+ codeHelper)
+
+ Return generator
+ End Function
+ End Class
+End Namespace
diff --git a/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTests.vb b/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTests.vb
index 80c6a15..f31ea30 100644
--- a/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTests.vb
+++ b/Test/EFCore.VisualBasic.Test/Migrations/Design/VisualBasicMigrationsGeneratorTests.vb
@@ -1,6 +1,5 @@
Imports System.Linq.Expressions
Imports System.Reflection
-Imports System.Text
Imports System.Text.RegularExpressions
Imports EntityFrameworkCore.VisualBasic.Design
Imports EntityFrameworkCore.VisualBasic.Design.Internal
@@ -22,13 +21,12 @@ Imports Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal
Imports Microsoft.EntityFrameworkCore.Storage
Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
Imports Microsoft.EntityFrameworkCore.TestUtilities
-Imports Microsoft.EntityFrameworkCore.ValueGeneration
Imports Microsoft.Extensions.DependencyInjection
Imports Xunit
Namespace Migrations.Design
- Public Class VisualBasicMigrationsGeneratorTests
+ Partial Public Class VisualBasicMigrationsGeneratorTests
Private Shared ReadOnly _nl As String = Environment.NewLine
Private Shared ReadOnly _toTable As String = _nl & "entityTypeBuilder.ToTable(""WithAnnotations"")"
@@ -113,10 +111,12 @@ Namespace Migrations.Design
RelationalAnnotationNames.TphMappingStrategy,
RelationalAnnotationNames.TptMappingStrategy,
RelationalAnnotationNames.RelationalModel,
+ RelationalAnnotationNames.RelationalModelFactory,
RelationalAnnotationNames.ModelDependencies,
RelationalAnnotationNames.FieldValueGetter,
RelationalAnnotationNames.JsonPropertyName,
RelationalAnnotationNames.ContainerColumnName, ' Appears On entity type but requires specific model (i.e. owned types that can map To json, otherwise validation throws)
+ RelationalAnnotationNames.ContainerColumnType,
RelationalAnnotationNames.ContainerColumnTypeMapping,
RelationalAnnotationNames.StoreType}
#Enable Warning BC40000 ' Type or member is obsolete
@@ -157,18 +157,13 @@ Namespace Migrations.Design
},
{
CoreAnnotationNames.DiscriminatorValue, ("MyDiscriminatorValue",
- _toTable & _nl &
- _nl &
- "entityTypeBuilder.HasDiscriminator" &
- "()." &
- NameOf(DiscriminatorBuilder.HasValue) &
- "(""MyDiscriminatorValue"")")
+ _toTable)
},
{
RelationalAnnotationNames.Comment, ("My Comment",
_nl &
"entityTypeBuilder.ToTable(""WithAnnotations""," & _nl &
- " Sub(t)" & _nl & _nl &
+ " Sub(t)" & _nl &
" t.HasComment(""My Comment"")" & _nl &
" End Sub)")
},
@@ -226,7 +221,9 @@ Namespace Migrations.Design
CoreAnnotationNames.DiscriminatorProperty,
CoreAnnotationNames.DiscriminatorValue,
CoreAnnotationNames.InverseNavigations,
+ CoreAnnotationNames.InverseNavigationsNoAttribute,
CoreAnnotationNames.NavigationCandidates,
+ CoreAnnotationNames.NavigationCandidatesNoAttribute,
CoreAnnotationNames.AmbiguousNavigations,
CoreAnnotationNames.DuplicateServiceProperties,
CoreAnnotationNames.AdHocModel,
@@ -273,9 +270,11 @@ Namespace Migrations.Design
RelationalAnnotationNames.TphMappingStrategy,
RelationalAnnotationNames.TptMappingStrategy,
RelationalAnnotationNames.RelationalModel,
+ RelationalAnnotationNames.RelationalModelFactory,
RelationalAnnotationNames.ModelDependencies,
RelationalAnnotationNames.FieldValueGetter,
RelationalAnnotationNames.ContainerColumnName,
+ RelationalAnnotationNames.ContainerColumnType,
RelationalAnnotationNames.ContainerColumnTypeMapping,
RelationalAnnotationNames.JsonPropertyName,
RelationalAnnotationNames.StoreType}
@@ -393,11 +392,30 @@ Namespace Migrations.Design
NameOf(CoreAnnotationNames) & "." & NameOf(CoreAnnotationNames.AllNames) & " doesn't contain " & annotationName)
Next
- For Each field In coreAnnotations.Concat(GetType(RelationalAnnotationNames).
- GetFields().
- Where(Function(f) f.Name <> "Prefix"))
+ Dim relationalAnnotations =
+ GetType(RelationalAnnotationNames).
+ GetFields().
+ Where(Function(f) f.FieldType = GetType(String) AndAlso f.Name <> "Prefix").ToList()
+
+ For Each field In relationalAnnotations
+ Dim annotationName = CStr(field.GetValue(Nothing))
+
+ If field.Name <> NameOf(RelationalAnnotationNames.TpcMappingStrategy) AndAlso
+ field.Name <> NameOf(RelationalAnnotationNames.TptMappingStrategy) AndAlso
+ field.Name <> NameOf(RelationalAnnotationNames.TphMappingStrategy) Then
+
+ Assert.True(
+ RelationalAnnotationNames.AllNames.Contains(annotationName),
+ NameOf(RelationalAnnotationNames) &
+ "." &
+ NameOf(RelationalAnnotationNames.AllNames) &
+ " doesn't contain " &
+ annotationName)
+ End If
+ Next
- Dim annotationName As String = CStr(field.GetValue(Nothing))
+ For Each field In coreAnnotations.Concat(relationalAnnotations)
+ Dim annotationName = CStr(field.GetValue(Nothing))
If Not invalidAnnotations.Contains(annotationName) Then
Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
@@ -414,7 +432,7 @@ Namespace Migrations.Design
' Generator should not throw--either update above, or add to ignored list in generator
test(generator, metadataItem, sb)
Catch e As Exception
- Assert.False(True, $"Annotation '{annotationName}' was not handled by the code generator: {e.Message}")
+ Assert.Fail($"Annotation '{annotationName}' was not handled by the code generator: {e.Message}")
End Try
Try
@@ -473,29 +491,30 @@ Namespace Migrations.Design
Public Sub Snapshot_with_enum_discriminator_uses_converted_values()
- Dim sqlServerTypeMappingSource1 As New SqlServerTypeMappingSource(
+ Dim sqlServerTypeMappingSource As New SqlServerTypeMappingSource(
TestServiceFactory.Instance.Create(Of TypeMappingSourceDependencies)(),
TestServiceFactory.Instance.Create(Of RelationalTypeMappingSourceDependencies)())
- Dim codeHelper As New VisualBasicHelper(sqlServerTypeMappingSource1)
+ Dim codeHelper As New VisualBasicHelper(sqlServerTypeMappingSource)
- Dim sqlServerAnnotationCodeGenerator1 As New SqlServerAnnotationCodeGenerator(
- New AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource1))
+ Dim sqlServerAnnotationCodeGenerator As New SqlServerAnnotationCodeGenerator(
+ New AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource))
Dim generator As New VisualBasicMigrationsGenerator(
New MigrationsCodeGeneratorDependencies(
- sqlServerTypeMappingSource1,
- sqlServerAnnotationCodeGenerator1),
+ sqlServerTypeMappingSource,
+ sqlServerAnnotationCodeGenerator),
codeHelper)
Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
modelBuilder.Model.RemoveAnnotation(CoreAnnotationNames.ProductVersion)
- modelBuilder.Entity(Of WithAnnotations)(Sub(eb)
- eb.HasDiscriminator(Of RawEnum)("EnumDiscriminator") _
- .HasValue(RawEnum.A) _
- .HasValue(Of Derived)(RawEnum.B)
- eb.Property(Of RawEnum)("EnumDiscriminator").HasConversion(Of Integer)()
- End Sub)
+ modelBuilder.Entity(Of WithAnnotations)(
+ Sub(eb)
+ eb.HasDiscriminator(Of RawEnum)("EnumDiscriminator").
+ HasValue(RawEnum.A).
+ HasValue(Of Derived)(RawEnum.B)
+ eb.Property(Of RawEnum)("EnumDiscriminator").HasConversion(Of Integer)()
+ End Sub)
Dim finalizedModel = modelBuilder.FinalizeModel(designTime:=True)
@@ -569,7 +588,8 @@ Namespace Migrations.Design
Dim migrationCode = generator.GenerateMigration("MyNamespace",
"MyMigration",
- {sqlOp,
+ {
+ sqlOp,
alterColumnOp,
AddColumnOperation,
InsertDataOperation
@@ -623,7 +643,7 @@ End Namespace
Dim modelBuilder = SqlServerTestHelpers.Instance.CreateConventionBuilder(configureConventions:=Sub(c) c.RemoveAllConventions())
modelBuilder.HasAnnotation("Some:EnumValue", RegexOptions.Multiline)
- modelBuilder.HasAnnotation(RelationalAnnotationNames.DbFunctions, New SortedDictionary(Of String, IDbFunction)())
+ modelBuilder.HasAnnotation(RelationalAnnotationNames.DbFunctions, New Dictionary(Of String, IDbFunction)())
modelBuilder.Entity("T1", Sub(eb)
eb.Property(Of Integer)("Id")
eb.Property(Of String)("C2").IsRequired()
@@ -648,8 +668,8 @@ Imports System.Text.RegularExpressions
Imports EntityFrameworkCore.VisualBasic.Migrations.Design
Imports Microsoft.EntityFrameworkCore
Imports Microsoft.EntityFrameworkCore.Infrastructure
-Imports Microsoft.EntityFrameworkCore.Metadata
Imports Microsoft.EntityFrameworkCore.Migrations
+Imports Microsoft.EntityFrameworkCore.Storage.ValueConversion
Imports Microsoft.VisualBasic
Namespace Global.MyNamespace
@@ -731,354 +751,15 @@ End Namespace
Public ReadOnly Property Id As Integer
End Class
-
- Public Sub Snapshots_compile()
- Dim generator = CreateMigrationsCodeGenerator()
-
- Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
-
- modelBuilder.Model.RemoveAnnotation(CoreAnnotationNames.ProductVersion)
- modelBuilder.Entity(Of EntityWithConstructorBinding)(
- Sub(x)
- x.Property(Function(e) e.Id)
-
- x.Property(Of Guid)("PropertyWithValueGenerator").HasValueGenerator(Of GuidValueGenerator)()
- End Sub)
- modelBuilder.HasDbFunction(Function() MyDbFunction())
-
- Dim model1 = modelBuilder.Model
- model1.Item("Some:EnumValue") = RegexOptions.Multiline
-
- Dim entityType = model1.AddEntityType("Cheese")
- Dim property1 = entityType.AddProperty("Pickle", GetType(StringBuilder))
- property1.SetValueConverter(New ValueConverter(Of StringBuilder, String)(
- Function(v) v.ToString(), Function(v) New StringBuilder(v), New ConverterMappingHints(size:=10)))
-
- Dim property2 = entityType.AddProperty("Ham", GetType(RawEnum))
- property2.SetValueConverter(New ValueConverter(Of RawEnum, String)(
- Function(v) v.ToString(),
- Function(v) DirectCast([Enum].Parse(GetType(RawEnum), v), RawEnum),
- New ConverterMappingHints(size:=10)))
-
- entityType.SetPrimaryKey(property2)
-
- Dim finalizedModel = modelBuilder.FinalizeModel(designTime:=True)
-
- Dim modelSnapshotCode = generator.GenerateSnapshot(
- "MyNamespace",
- GetType(MyContext),
- "MySnapshot",
- finalizedModel)
-
- Assert.Equal(
-"'
-Imports System
-Imports System.Text.RegularExpressions
-Imports EntityFrameworkCore.VisualBasic.Migrations.Design
-Imports Microsoft.EntityFrameworkCore
-Imports Microsoft.EntityFrameworkCore.Infrastructure
-Imports Microsoft.EntityFrameworkCore.Metadata
-Imports Microsoft.EntityFrameworkCore.Migrations
-Imports Microsoft.VisualBasic
-
-Namespace Global.MyNamespace
-
- Partial Class MySnapshot
- Inherits ModelSnapshot
-
- Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
- modelBuilder.HasAnnotation(""Some:EnumValue"", RegexOptions.Multiline)
-
- modelBuilder.Entity(""Cheese"",
- Sub(b)
- b.Property(Of String)(""Ham"").
- HasColumnType(""just_string(10)"")
-
- b.Property(Of String)(""Pickle"").
- HasColumnType(""just_string(10)"")
-
- b.HasKey(""Ham"")
-
- b.ToTable(""Cheese"")
- End Sub)
-
- modelBuilder.Entity(""EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithConstructorBinding"",
- Sub(b)
- b.Property(Of Integer)(""Id"").
- ValueGeneratedOnAdd().
- HasColumnType(""default_int_mapping"")
-
- b.Property(Of Guid)(""PropertyWithValueGenerator"").
- HasColumnType(""default_guid_mapping"")
-
- b.HasKey(""Id"")
-
- b.ToTable(""EntityWithConstructorBinding"")
- End Sub)
- End Sub
- End Class
-End Namespace
-", modelSnapshotCode, ignoreLineEndingDifferences:=True)
-
- Dim snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot")
- Assert.Equal(2, snapshot.Model.GetEntityTypes().Count())
- End Sub
-
-
- Public Sub Snapshot_with_default_values_are_round_tripped()
- Dim generator = CreateMigrationsCodeGenerator()
-
- Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
- modelBuilder.Entity(Of EntityWithEveryPrimitive)(
- Sub(eb)
- eb.Property(Function(e) e.Boolean).HasDefaultValue(False)
- eb.Property(Function(e) e.Byte).HasDefaultValue(Byte.MinValue)
- eb.Property(Function(e) e.ByteArray).HasDefaultValue(New Byte() {0})
- eb.Property(Function(e) e.Char).HasDefaultValue("0"c)
- eb.Property(Function(e) e.Date).HasDefaultValue(Date.MinValue)
- eb.Property(Function(e) e.DateTimeOffset).HasDefaultValue(DateTimeOffset.MinValue)
- eb.Property(Function(e) e.Decimal).HasDefaultValue(Decimal.MinValue)
- eb.Property(Function(e) e.Double).HasDefaultValue(Double.MinValue) 'double.NegativeInfinity
- eb.Property(Function(e) e.Enum).HasDefaultValue(Enum1.Default)
- eb.Property(Function(e) e.NullableEnum).HasDefaultValue(Enum1.Default).HasConversion(Of String)()
- eb.Property(Function(e) e.Guid).HasDefaultValue(Guid.NewGuid())
- eb.Property(Function(e) e.Int16).HasDefaultValue(Short.MaxValue)
- eb.Property(Function(e) e.Int32).HasDefaultValue(Integer.MaxValue)
- eb.Property(Function(e) e.Int64).HasDefaultValue(Long.MaxValue)
- eb.Property(Function(e) e.Single).HasDefaultValue(Single.Epsilon)
- eb.Property(Function(e) e.SByte).HasDefaultValue(SByte.MinValue)
- eb.Property(Function(e) e.String).HasDefaultValue("""")
- eb.Property(Function(e) e.TimeSpan).HasDefaultValue(TimeSpan.MaxValue)
- eb.Property(Function(e) e.UInt16).HasDefaultValue(UShort.MinValue)
- eb.Property(Function(e) e.UInt32).HasDefaultValue(UInteger.MinValue)
- eb.Property(Function(e) e.UInt64).HasDefaultValue(ULong.MinValue)
- eb.Property(Function(e) e.NullableBoolean).HasDefaultValue(True)
- eb.Property(Function(e) e.NullableByte).HasDefaultValue(Byte.MaxValue)
- eb.Property(Function(e) e.NullableChar).HasDefaultValue("'"c)
- eb.Property(Function(e) e.NullableDate).HasDefaultValue(Date.MaxValue)
- eb.Property(Function(e) e.NullableDateTimeOffset).HasDefaultValue(DateTimeOffset.MaxValue)
- eb.Property(Function(e) e.NullableDecimal).HasDefaultValue(Decimal.MaxValue)
- eb.Property(Function(e) e.NullableDouble).HasDefaultValue(0.6822871999174)
- eb.Property(Function(e) e.NullableEnum).HasDefaultValue(Enum1.One Or Enum1.Two)
- eb.Property(Function(e) e.NullableStringEnum).HasDefaultValue(Enum1.One).HasConversion(Of String)()
- eb.Property(Function(e) e.NullableGuid).HasDefaultValue(New Guid)
- eb.Property(Function(e) e.NullableInt16).HasDefaultValue(Short.MinValue)
- eb.Property(Function(e) e.NullableInt32).HasDefaultValue(Integer.MinValue)
- eb.Property(Function(e) e.NullableInt64).HasDefaultValue(Long.MinValue)
- eb.Property(Function(e) e.NullableSingle).HasDefaultValue(0.3333333F)
- eb.Property(Function(e) e.NullableSByte).HasDefaultValue(SByte.MinValue)
- eb.Property(Function(e) e.NullableTimeSpan).HasDefaultValue(TimeSpan.MinValue.Add(New TimeSpan))
- eb.Property(Function(e) e.NullableUInt16).HasDefaultValue(UShort.MaxValue)
- eb.Property(Function(e) e.NullableUInt32).HasDefaultValue(UInteger.MaxValue)
- eb.Property(Function(e) e.NullableUInt64).HasDefaultValue(ULong.MaxValue)
-
- eb.HasKey(Function(e) e.Boolean)
- End Sub)
-
- Dim finalizedModel = modelBuilder.FinalizeModel(designTime:=True)
-
- Dim modelSnapshotCode = generator.GenerateSnapshot(
- "MyNamespace",
- GetType(MyContext),
- "MySnapshot",
- finalizedModel)
-
- Dim snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot")
- Dim entityType = snapshot.Model.GetEntityTypes().Single()
-
- Assert.Equal(GetType(EntityWithEveryPrimitive).FullName & " (Dictionary)", entityType.DisplayName())
-
- For Each prop In modelBuilder.Model.GetEntityTypes().Single().GetProperties()
- Dim expected = prop.GetDefaultValue()
- Dim actual = entityType.FindProperty(prop.Name).GetDefaultValue()
-
- If actual IsNot Nothing AndAlso expected IsNot Nothing Then
- If expected.GetType().IsEnum Then
- If TypeOf actual Is String Then
- Dim actualString = actual.ToString()
- actual = [Enum].Parse(expected.GetType(), actualString)
- Else
- actual = [Enum].ToObject(expected.GetType(), actual)
- End If
- End If
-
- If actual.GetType() <> expected.GetType() Then
- actual = Convert.ChangeType(actual, expected.GetType())
- End If
- End If
-
- Assert.Equal(expected, actual)
- Next
- End Sub
-
- Private Class EntityWithEveryPrimitive
- Public Property [Boolean] As Boolean
- Public Property [Byte] As Byte
- Public Property ByteArray As Byte()
- Public Property [Char] As Char
- Public Property [Date] As Date
- Public Property DateTimeOffset As DateTimeOffset
- Public Property [Decimal] As Decimal
- Public Property [Double] As Double
- Public Property [Enum] As Enum1
- Public Property StringEnum As Enum1
- Public Property Guid As Guid
- Public Property Int16 As Short
- Public Property Int32 As Integer
- Public Property Int64 As Long
- Public Property NullableBoolean As Boolean?
- Public Property NullableByte As Byte?
- Public Property NullableChar As Char?
- Public Property NullableDate As Date?
- Public Property NullableDateTimeOffset As DateTimeOffset?
- Public Property NullableDecimal As Decimal?
- Public Property NullableDouble As Double?
- Public Property NullableEnum As Enum1?
- Public Property NullableStringEnum As Enum1?
- Public Property NullableGuid As Guid?
- Public Property NullableInt16 As Short?
- Public Property NullableInt32 As Integer?
- Public Property NullableInt64 As Long?
- Public Property NullableSByte As SByte?
- Public Property NullableSingle As Single?
- Public Property NullableTimeSpan As TimeSpan?
- Public Property NullableUInt16 As UShort?
- Public Property NullableUInt32 As UInteger?
- Public Property NullableUInt64 As ULong?
- Private _privateSetter As Integer
- Public Property PrivateSetter As Integer
- Get
- Return _privateSetter
- End Get
- Private Set
- _privateSetter = Value
- End Set
- End Property
- Public Property [SByte] As SByte
- Public Property [Single] As Single
- Public Property [String] As String
- Public Property TimeSpan As TimeSpan
- Public Property UInt16 As UShort
- Public Property UInt32 As UInteger
- Public Property UInt64 As ULong
- End Class
-
-
- Public Enum Enum1
- [Default] = 0
- One = 1
- Two = 2
- End Enum
-
-
- Public Sub Complex_properties_are_genered_in_snapshot()
-
- Dim generator = CreateMigrationsCodeGenerator()
-
- Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
- modelBuilder.Model.RemoveAnnotation(CoreAnnotationNames.ProductVersion)
-
- modelBuilder.Entity(Of EntityWithOneProperty)(
- Sub(e)
- e.ComplexProperty(Function(eo) eo.EntityWithTwoProperties,
- Sub(eb As ComplexPropertyBuilder(Of EntityWithTwoProperties))
- eb.Property(Function(x) x.AlternateId).HasColumnOrder(1)
- eb.ComplexProperty(Function(x) x.EntityWithStringKey,
- Sub(eb2 As ComplexPropertyBuilder(Of EntityWithStringKey))
- eb2.IsRequired()
- End Sub)
- eb.IsRequired()
- End Sub)
- End Sub)
-
- Dim finalizedModel = modelBuilder.FinalizeModel(designTime:=True)
-
- Dim modelSnapshotCode = generator.GenerateSnapshot(
- "MyNamespace",
- GetType(MyContext),
- "MySnapshot",
- finalizedModel)
-
- Assert.Equal(
-
-Imports System.Collections.Generic
-Imports EntityFrameworkCore.VisualBasic.Migrations.Design
-Imports Microsoft.EntityFrameworkCore
-Imports Microsoft.EntityFrameworkCore.Infrastructure
-Imports Microsoft.EntityFrameworkCore.Metadata
-Imports Microsoft.EntityFrameworkCore.Migrations
-Imports Microsoft.VisualBasic
-
-Namespace Global.MyNamespace
-
- Partial Class MySnapshot
- Inherits ModelSnapshot
-
- Protected Overrides Sub BuildModel(modelBuilder As ModelBuilder)
-
- modelBuilder.Entity("EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty",
- Sub(b)
- b.Property(Of Integer)("Id").
- ValueGeneratedOnAdd().
- HasColumnType("default_int_mapping")
-
- b.ComplexProperty(Of Dictionary(Of String, Object))("EntityWithTwoProperties", "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties",
- Sub(b1)
- b1.IsRequired()
-
- b1.Property(Of Integer)("AlternateId").
- HasColumnType("default_int_mapping").
- HasColumnOrder(1)
-
- b1.Property(Of Integer)("Id").
- HasColumnType("default_int_mapping")
-
- b1.ComplexProperty(Of Dictionary(Of String, Object))("EntityWithStringKey", "EntityFrameworkCore.VisualBasic.Migrations.Design.VisualBasicMigrationsGeneratorTests+EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties.EntityWithStringKey#EntityWithStringKey",
- Sub(b2)
- b2.IsRequired()
-
- b2.Property(Of String)("Id").
- HasColumnType("just_string(max)")
- End Sub)
- End Sub)
-
- b.HasKey("Id")
-
- b.ToTable("EntityWithOneProperty")
- End Sub)
- End Sub
- End Class
-End Namespace
-]]>.Value, modelSnapshotCode, ignoreLineEndingDifferences:=True)
-
- Dim snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot")
- End Sub
-
- Private Class EntityWithOneProperty
- Public Property Id As Integer
- Public Property EntityWithTwoProperties As EntityWithTwoProperties
- End Class
-
- Private Class EntityWithTwoProperties
- Public Property Id As Integer
- Public Property AlternateId As Integer
- Public Property EntityWithStringKey As EntityWithStringKey
- End Class
+ Private Function CompileModelSnapshot(code As String, modelSnapshotTypeName As String) As ModelSnapshot
- Private Class EntityWithStringKey
- Public Property Id As String
- End Class
-
- Private Function CompileModelSnapshot(modelSnapshotCode As String, modelSnapshotTypeName As String) As ModelSnapshot
Dim build As New BuildSource With {
- .Sources = New Dictionary(Of String, String) From {{"MigrationSnapshot.vb", modelSnapshotCode}}
+ .Sources = New Dictionary(Of String, String) From {{"Snapshot.vb", code}}
}
- With build.References
- .Add(BuildReference.ByName("Microsoft.EntityFrameworkCore"))
- .Add(BuildReference.ByName("Microsoft.EntityFrameworkCore.Relational"))
- .Add(BuildReference.ByName(GetType(VisualBasicMigrationsGeneratorTests).Assembly.GetName().Name))
- End With
+ For Each buildReference In GetReferences()
+ build.References.Add(buildReference)
+ Next
Dim assembly = build.BuildInMemory()
@@ -1165,157 +846,6 @@ End Namespace
Assert.Contains("Imports System.Text.RegularExpressions", migration)
End Sub
-
- Public Sub Data_seedings_With_HasData_is_generated_correctly()
- Dim Generator = CreateMigrationsCodeGenerator()
-
- Dim MyModelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
-
- MyModelBuilder.Entity(Of SimpleEntity)(Sub(eb)
- eb.HasData({
- New SimpleEntity With {
- .Id = 1,
- .Name = "Name1"
- },
- New SimpleEntity With {
- .Id = 2,
- .Name = "Name2"
- }})
- End Sub)
-
- Dim finalizedModel = MyModelBuilder.FinalizeModel(designTime:=True)
-
- Dim SnapshotCode = Generator.GenerateSnapshot(
- "MyNamespace",
- GetType(MyContext),
- "MySnapshot",
- finalizedModel
- )
-
- Dim migrationMetadataCode = Generator.GenerateMetadata(
- "MyNamespace",
- GetType(MyContext),
- "MyMigration",
- "20210515113700_MyMigration",
- finalizedModel
- )
-
- Dim expectedCode =
-" b.HasData({
- New With {
- .Id = 1,
- .Name = ""Name1""
- },
- New With {
- .Id = 2,
- .Name = ""Name2""
- }
- })"
-
- AssertContains(expectedCode, SnapshotCode)
- AssertContains(expectedCode, migrationMetadataCode)
- End Sub
-
- Private Class SimpleEntity
- Property Id As Integer
- Property Name As String
- End Class
-
-
- Public Sub Sequence_is_generated_correctly()
-
- Dim modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
-
- modelBuilder.HasSequence(Of Integer)("OrderNumbers", "Shared").
- StartsAt(1000).
- IncrementsBy(5).
- HasMin(500).
- HasMax(10_000).
- IsCyclic()
-
- Dim MyModel = modelBuilder.FinalizeModel()
-
- Dim sqlServerTypeMappingSource As New SqlServerTypeMappingSource(
- TestServiceFactory.Instance.Create(Of TypeMappingSourceDependencies)(),
- TestServiceFactory.Instance.Create(Of RelationalTypeMappingSourceDependencies)())
-
- Dim codeHelper As New VisualBasicHelper(sqlServerTypeMappingSource)
-
- Dim sqlServerAnnotationCodeGenerator As New SqlServerAnnotationCodeGenerator(
- New AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource))
-
- Dim generator As New TestVisualBasicSnapshotGenerator(codeHelper,
- sqlServerTypeMappingSource,
- sqlServerAnnotationCodeGenerator)
-
- Dim sb As New IndentedStringBuilder
-
- For Each sequence In MyModel.GetSequences()
- generator.TestGenerateSequence("MyModelBuilder", sequence, sb)
- Next
-
- Dim expected As String =
-"
-MyModelBuilder.HasSequence(Of Integer)(""OrderNumbers"", ""Shared"").
- StartsAt(1000L).
- IncrementsBy(5).
- HasMin(500L).
- HasMax(10000L).
- IsCyclic()
-"
-
- Assert.Equal(expected, sb.ToString(), ignoreLineEndingDifferences:=True)
- End Sub
-
-
- Public Sub Index_is_generated_correctly()
-
- Dim MyModelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder()
-
- MyModelBuilder.Entity(Of SimpleEntity)(Sub(eb)
- eb.HasIndex(Function(e) New With {e.Id, e.Name}).
- HasDatabaseName("Index1").
- IsUnique()
-
- eb.HasIndex({"Name"}, "Index2").
- HasFilter("[Name] IS NOT NULL").
- HasAnnotation("MyAnnotation", "ABC")
- End Sub)
-
- Dim MyModel = MyModelBuilder.FinalizeModel(designTime:=True)
- Dim k = MyModel.FindEntityType(GetType(SimpleEntity))
-
- Dim sqlServerTypeMappingSource As New SqlServerTypeMappingSource(
- TestServiceFactory.Instance.Create(Of TypeMappingSourceDependencies)(),
- TestServiceFactory.Instance.Create(Of RelationalTypeMappingSourceDependencies)())
-
- Dim codeHelper As New VisualBasicHelper(sqlServerTypeMappingSource)
-
- Dim sqlServerAnnotationCodeGenerator As New SqlServerAnnotationCodeGenerator(
- New AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource))
-
- Dim Generator As New TestVisualBasicSnapshotGenerator(codeHelper,
- sqlServerTypeMappingSource,
- sqlServerAnnotationCodeGenerator)
-
- Dim sb As New IndentedStringBuilder
-
- Generator.TestGenerateIndexes("MyModelBuilder", MyModel.FindEntityType(GetType(SimpleEntity)).GetIndexes, sb)
-
- Dim expected As String =
-"
-MyModelBuilder.HasIndex(""Id"", ""Name"").
- IsUnique().
- HasDatabaseName(""Index1"")
-
-MyModelBuilder.HasIndex({""Name""}, ""Index2"").
- HasFilter(""[Name] IS NOT NULL"").
- HasAnnotation(""MyAnnotation"", ""ABC"")
-"
-
- Assert.Equal(expected, sb.ToString(), ignoreLineEndingDifferences:=True)
- End Sub
-
Private Shared Function CreateMigrationsCodeGenerator() As IMigrationsCodeGenerator
Dim testAssembly As Assembly = GetType(VisualBasicMigrationsGeneratorTests).Assembly
@@ -1332,9 +862,7 @@ MyModelBuilder.HasIndex({""Name""}, ""Index2"").
GetRequiredService(Of IMigrationsCodeGenerator)()
End Function
- Private Shared Sub AssertContains(expected As String,
- actual As String)
-
+ Private Shared Sub AssertContains(expected As String, actual As String)
' Normalize line endings to Environment.Newline
expected = expected.Replace(vbCrLf, vbLf).
Replace(vbLf & vbCr, vbLf).
diff --git a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/ModelCodeGeneratorTestFixture.vb b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/ModelCodeGeneratorTestFixture.vb
index e375221..118dae4 100644
--- a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/ModelCodeGeneratorTestFixture.vb
+++ b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/ModelCodeGeneratorTestFixture.vb
@@ -6,7 +6,7 @@ Namespace Scaffolding.Internal
Public Class ModelCodeGeneratorTestFixture
Implements IDisposable
- Public ReadOnly Property ProjectDir As TempDirectory = New TempDirectory()
+ Public ReadOnly Property ProjectDir As New TempDirectory()
Public Sub New()
Dim templatesDir = Path.Combine(ProjectDir, "CodeTemplates", "EFCore")
@@ -21,10 +21,10 @@ Namespace Scaffolding.Internal
"EFCore")
Dim destDbContext = Path.Combine(templatesDir, "DbContext.t4")
- File.Copy(Path.Combine(VBTemplatesDir, "DbContext.t4"), destDbContext)
+ File.Copy(Path.Combine(VBTemplatesDir, "DbContext.t4"), destDbContext, True)
Dim destEntityType = Path.Combine(templatesDir, "EntityType.t4")
- File.Copy(Path.Combine(VBTemplatesDir, "EntityType.t4"), destEntityType)
+ File.Copy(Path.Combine(VBTemplatesDir, "EntityType.t4"), destEntityType, True)
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
diff --git a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicDbContextGeneratorTest.vb b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicDbContextGeneratorTest.vb
index 0157b2d..17694a9 100644
--- a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicDbContextGeneratorTest.vb
+++ b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicDbContextGeneratorTest.vb
@@ -981,7 +981,7 @@ End Namespace
},
Sub(code) AssertContains(".
IsFixedLength()", code.ContextFile.Code),
- Sub(model) Assert.Equal(True, model.FindEntityType("TestNamespace.Employee").GetProperty("Name").IsFixedLength())
+ Sub(model) Assert.True(model.FindEntityType("TestNamespace.Employee").GetProperty("Name").IsFixedLength())
)
End Sub
@@ -1283,11 +1283,11 @@ Namespace TestNamespace
entity.ToTable(Sub(tb) tb.IsTemporal(Sub(ttb)
ttb.UseHistoryTable(""CustomerHistory"")
ttb.
- HasPeriodStart(""PeriodStart"").
- HasColumnName(""PeriodStart"")
+ HasPeriodStart(""PeriodStart"").
+ HasColumnName(""PeriodStart"")
ttb.
- HasPeriodEnd(""PeriodEnd"").
- HasColumnName(""PeriodEnd"")
+ HasPeriodEnd(""PeriodEnd"").
+ HasColumnName(""PeriodEnd"")
End Sub))
End Sub)
@@ -1610,13 +1610,15 @@ End Namespace
End Sub)
End Sub
- Protected Overrides Sub AddModelServices(services As IServiceCollection)
- services.Replace(ServiceDescriptor.Singleton(Of IRelationalAnnotationProvider, TestModelAnnotationProvider)())
- End Sub
+ Protected Overrides Function AddModelServices(services As IServiceCollection) As IServiceCollection
+ Return services.Replace(
+ ServiceDescriptor.Singleton(Of IRelationalAnnotationProvider, TestModelAnnotationProvider)())
+ End Function
- Protected Overrides Sub AddScaffoldingServices(services As IServiceCollection)
- services.Replace(ServiceDescriptor.Singleton(Of IAnnotationCodeGenerator, TestModelAnnotationCodeGenerator)())
- End Sub
+ Protected Overrides Function AddScaffoldingServices(services As IServiceCollection) As IServiceCollection
+ Return services.Replace(
+ ServiceDescriptor.Singleton(Of IAnnotationCodeGenerator, TestModelAnnotationCodeGenerator)())
+ End Function
Private Class TestModelAnnotationProvider
Inherits SqlServerAnnotationProvider
diff --git a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicEntityTypeGeneratorTest.vb b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicEntityTypeGeneratorTest.vb
index 8d4b0a2..de49cbe 100644
--- a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicEntityTypeGeneratorTest.vb
+++ b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicEntityTypeGeneratorTest.vb
@@ -2901,13 +2901,15 @@ End Namespace
End Sub)
End Sub
- Protected Overrides Sub AddModelServices(services As IServiceCollection)
- services.Replace(ServiceDescriptor.Singleton(Of IRelationalAnnotationProvider, TestModelAnnotationProvider)())
- End Sub
-
- Protected Overrides Sub AddScaffoldingServices(services As IServiceCollection)
- services.Replace(ServiceDescriptor.Singleton(Of IAnnotationCodeGenerator, TestModelAnnotationCodeGenerator)())
- End Sub
+ Protected Overrides Function AddModelServices(services As IServiceCollection) As IServiceCollection
+ Return services.Replace(
+ ServiceDescriptor.Singleton(Of IRelationalAnnotationProvider, TestModelAnnotationProvider)())
+ End Function
+
+ Protected Overrides Function AddScaffoldingServices(services As IServiceCollection) As IServiceCollection
+ Return services.Replace(
+ ServiceDescriptor.Singleton(Of IAnnotationCodeGenerator, TestModelAnnotationCodeGenerator)())
+ End Function
Private Class TestModelAnnotationProvider
Inherits SqlServerAnnotationProvider
diff --git a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelCodeGeneratorTestBase.vb b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelCodeGeneratorTestBase.vb
index 3863a67..19bdd18 100644
--- a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelCodeGeneratorTestBase.vb
+++ b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelCodeGeneratorTestBase.vb
@@ -30,20 +30,20 @@ Namespace Scaffolding.Internal
assertModel As Action(Of IModel),
Optional skipBuild As Boolean = False)
- Dim designServices As New ServiceCollection()
- AddModelServices(designServices)
+ Dim modelBuilder = SqlServerTestHelpers.
+ Instance.
+ CreateConventionBuilder(addServices:=AddressOf AddModelServices)
- Dim modelBuilder = SqlServerTestHelpers.Instance.CreateConventionBuilder(customServices:=designServices)
buildModel(modelBuilder)
- Dim Model = modelBuilder.FinalizeModel(designTime:=True, skipValidation:=True)
+ Dim model = modelBuilder.FinalizeModel(designTime:=True, skipValidation:=True)
Dim services = CreateServices()
AddScaffoldingServices(services)
Dim serviceProvider = services.BuildServiceProvider(validateScopes:=True)
- Test(serviceProvider, Model, options, assertScaffold, assertModel, skipBuild)
+ Test(serviceProvider, model, options, assertScaffold, assertModel, skipBuild)
End Sub
Protected Sub Test(buildModel As Func(Of IServiceProvider, IModel),
@@ -146,8 +146,8 @@ Namespace Scaffolding.Internal
Function CreateServices() As IServiceCollection
Dim testAssembly = GetType(VisualBasicModelCodeGeneratorTestBase).Assembly
Dim reporter = New TestOperationReporter(_output)
- Dim services = New DesignTimeServicesBuilder(testAssembly, testAssembly, reporter, New String() {}).
- CreateServiceCollection("Microsoft.EntityFrameworkCore.SqlServer")
+ Dim services = New DesignTimeServicesBuilder(testAssembly, testAssembly, reporter, Array.Empty(Of String)()).
+ CreateServiceCollection("Microsoft.EntityFrameworkCore.SqlServer")
Dim vbServices As New EFCoreVisualBasicServices
vbServices.ConfigureDesignTimeServices(services)
@@ -155,11 +155,13 @@ Namespace Scaffolding.Internal
Return services
End Function
- Protected Overridable Sub AddModelServices(services As IServiceCollection)
- End Sub
+ Protected Overridable Function AddModelServices(services As IServiceCollection) As IServiceCollection
+ Return services
+ End Function
- Protected Overridable Sub AddScaffoldingServices(services As IServiceCollection)
- End Sub
+ Protected Overridable Function AddScaffoldingServices(services As IServiceCollection) As IServiceCollection
+ Return services
+ End Function
Protected Shared Sub AssertFileContents(expectedCode As String,
file As ScaffoldedFile)
diff --git a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelGeneratorTest.vb b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelGeneratorTest.vb
index 1683a8d..e033ea9 100644
--- a/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelGeneratorTest.vb
+++ b/Test/EFCore.VisualBasic.Test/Scaffolding/Internal/VisualBasicModelGeneratorTest.vb
@@ -51,7 +51,7 @@ Namespace Scaffolding.Internal
Dim testAssembly As Assembly = GetType(VisualBasicModelGeneratorTest).Assembly
Dim reporter As New TestOperationReporter
- Dim services = New DesignTimeServicesBuilder(testAssembly, testAssembly, reporter, New String() {}).
+ Dim services = New DesignTimeServicesBuilder(testAssembly, testAssembly, reporter, Array.Empty(Of String)()).
CreateServiceCollection("Microsoft.EntityFrameworkCore.SqlServer").
AddSingleton(Of IAnnotationCodeGenerator, AnnotationCodeGenerator)().
AddSingleton(Of IProviderConfigurationCodeGenerator, TestProviderCodeGenerator)()
diff --git a/Test/EFCore.VisualBasic.Test/TestUtilities/BuildSource.vb b/Test/EFCore.VisualBasic.Test/TestUtilities/BuildSource.vb
index abb6d37..c2cfb10 100644
--- a/Test/EFCore.VisualBasic.Test/TestUtilities/BuildSource.vb
+++ b/Test/EFCore.VisualBasic.Test/TestUtilities/BuildSource.vb
@@ -138,7 +138,9 @@ All diagnostics:
_ ' Unused import statement.
{"BC50001", ReportDiagnostic.Suppress},
_ ' Casing of namespace Namespace does not match casing of namespace Namespace
- {"BC40055", ReportDiagnostic.Suppress}
+ {"BC40055", ReportDiagnostic.Suppress},
+ _ ' is obsolete
+ {"BC40000", ReportDiagnostic.Suppress}
})
End Function
End Class
diff --git a/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/Metadata/RelationalModelTest.vb b/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/Metadata/RelationalModelTest.vb
index d95206d..eb6ad03 100644
--- a/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/Metadata/RelationalModelTest.vb
+++ b/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/Metadata/RelationalModelTest.vb
@@ -1,374 +1,11 @@
-Imports Microsoft.EntityFrameworkCore
-Imports Microsoft.EntityFrameworkCore.Metadata
-Imports Microsoft.EntityFrameworkCore.Metadata.Internal
+Imports Microsoft.EntityFrameworkCore.Metadata
Imports Microsoft.EntityFrameworkCore.TestUtilities
-Imports Xunit
Namespace Metadata
Public Module RelationalModelTest
Public Sub AssertEqual(expectedModel As IRelationalModel, actualModel As IRelationalModel)
- DirectCast(expectedModel, RelationalModel).DefaultTables.Values.ZipAssert(
- DirectCast(actualModel, RelationalModel).DefaultTables.Values, AddressOf AssertEqual)
-
- expectedModel.Tables.ZipAssert(actualModel.Tables, AddressOf AssertEqual)
- expectedModel.Views.ZipAssert(actualModel.Views, AddressOf AssertEqual)
- expectedModel.Queries.ZipAssert(actualModel.Queries, AddressOf AssertEqual)
- expectedModel.Functions.ZipAssert(actualModel.Functions, AddressOf AssertEqual)
- expectedModel.StoredProcedures.ZipAssert(actualModel.StoredProcedures, AddressOf AssertEqual)
-
- Assert.Equal(DirectCast(expectedModel, RelationalModel).IsReadOnly, (DirectCast(actualModel, RelationalModel)).IsReadOnly)
- Assert.Equal(expectedModel.GetAnnotations(), actualModel.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expectedModel.GetRuntimeAnnotations(), actualModel.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Private Sub AssertEqualBase(expected As ITableBase, actual As ITableBase)
- Assert.Equal(expected.Name, actual.Name)
- Assert.Equal(expected.Schema, actual.Schema)
- Assert.Equal(expected.IsShared, actual.IsShared)
-
- For Each expectedEntityType In expected.EntityTypeMappings.Select(Function(m) m.TypeBase).Cast(Of IEntityType)
- Dim actualEntityType = DirectCast(actual.EntityTypeMappings.Single(Function(m) m.TypeBase.Name = expectedEntityType.Name).TypeBase, IEntityType)
- Assert.Equal(expected.GetRowInternalForeignKeys(expectedEntityType).Count(),
- actual.GetRowInternalForeignKeys(actualEntityType).Count())
- Assert.Equal(expected.GetReferencingRowInternalForeignKeys(expectedEntityType).Count(),
- actual.GetReferencingRowInternalForeignKeys(actualEntityType).Count())
- Next
-
- For Each expectedEntityType In expected.ComplexTypeMappings.Select(Function(m) m.TypeBase)
- Dim actualEntityType = actual.ComplexTypeMappings.Single(Function(m) m.TypeBase.Name = expectedEntityType.Name).TypeBase
- Next
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As ITableBase, actual As ITableBase)
- AssertEqualBase(expected, actual)
-
- expected.Columns.ZipAssert(actual.Columns, AddressOf AssertEqual)
- expected.EntityTypeMappings.ZipAssert(actual.EntityTypeMappings, AddressOf AssertEqual)
-
- Assert.Same(actual, DirectCast(actual.Model, RelationalModel).DefaultTables(actual.Name))
- End Sub
-
- Public Sub AssertEqualBase(expected As ITableMappingBase, actual As ITableMappingBase)
- Assert.Equal(expected.TypeBase.Name, actual.TypeBase.Name)
- Assert.Equal(expected.Table.SchemaQualifiedName, actual.Table.SchemaQualifiedName)
- Assert.Equal(expected.IncludesDerivedTypes, actual.IncludesDerivedTypes)
- Assert.Equal(expected.IsSharedTablePrincipal, actual.IsSharedTablePrincipal)
- Assert.Equal(expected.IsSplitEntityTypePrincipal, actual.IsSplitEntityTypePrincipal)
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As ITableMappingBase, actual As ITableMappingBase)
- AssertEqualBase(expected, actual)
-
- expected.ColumnMappings.ZipAssert(actual.ColumnMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqualBase(expected As IColumnBase, actual As IColumnBase)
- Assert.Equal(expected.Name, actual.Name)
- Assert.Equal(expected.IsNullable, actual.IsNullable)
- Assert.Equal(expected.ProviderClrType, actual.ProviderClrType)
- Assert.Equal(expected.StoreType, actual.StoreType)
- Assert.Equal(expected.StoreTypeMapping.StoreType, actual.StoreTypeMapping.StoreType)
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IColumnBase, actual As IColumnBase)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.Table.FindColumn(actual.Name))
- End Sub
-
- Public Sub AssertEqualBase(expected As IColumnMappingBase, actual As IColumnMappingBase)
- Assert.Equal(expected.Column.Name, actual.Column.Name)
- Assert.Equal(expected.Property.Name, actual.Property.Name)
- Assert.Equal(expected.TypeMapping.StoreType, actual.TypeMapping.StoreType)
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IColumnMappingBase, actual As IColumnMappingBase)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.TableMapping.ColumnMappings)
- End Sub
-
- Public Sub AssertEqual(expected As ITable, actual As ITable)
- AssertEqualBase(expected, actual)
-
- expected.Columns.ZipAssert(actual.Columns, AddressOf AssertEqual)
- expected.Indexes.ZipAssert(actual.Indexes, AddressOf AssertEqual)
- expected.ForeignKeyConstraints.ZipAssert(actual.ForeignKeyConstraints, AddressOf AssertEqual)
- expected.ReferencingForeignKeyConstraints.ZipAssert(actual.ReferencingForeignKeyConstraints, AddressOf AssertEqual)
- expected.UniqueConstraints.ZipAssert(actual.UniqueConstraints, AddressOf AssertEqual)
- expected.Triggers.ZipAssert(actual.Triggers, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.Model.FindTable(actual.Name, actual.Schema))
- expected.EntityTypeMappings.ZipAssert(actual.EntityTypeMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As ITableMapping, actual As ITableMapping)
- AssertEqualBase(expected, actual)
-
- AssertEqual(expected.DeleteStoredProcedureMapping, actual.DeleteStoredProcedureMapping)
- AssertEqual(expected.InsertStoredProcedureMapping, actual.InsertStoredProcedureMapping)
- AssertEqual(expected.UpdateStoredProcedureMapping, actual.UpdateStoredProcedureMapping)
-
- expected.ColumnMappings.ZipAssert(actual.ColumnMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As IColumn, actual As IColumn)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.Table.FindColumn(actual.Name))
- End Sub
-
- Public Sub AssertEqual(expected As IColumnMapping, actual As IColumnMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.TableMapping.ColumnMappings)
- End Sub
-
- Public Sub AssertEqual(expected As ITableIndex, actual As ITableIndex)
- Assert.Equal(expected.Columns.Select(Function(c) c.Name), actual.Columns.Select(Function(c) c.Name))
- Assert.Equal(expected.Name, actual.Name)
- Assert.Contains(actual, actual.Table.Indexes)
- Assert.Equal(actual.MappedIndexes.Select(Function(i) i.Properties.Select(Function(p) p.Name)),
- expected.MappedIndexes.Select(Function(i) i.Properties.Select(Function(p) p.Name)))
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IForeignKeyConstraint, actual As IForeignKeyConstraint)
- Assert.Equal(expected.Columns.Select(Function(c) c.Name), actual.Columns.Select(Function(c) c.Name))
- Assert.Equal(expected.PrincipalColumns.Select(Function(c) c.Name), actual.PrincipalColumns.Select(Function(c) c.Name))
- Assert.Equal(expected.Name, actual.Name)
- Assert.Equal(expected.OnDeleteAction, actual.OnDeleteAction)
- Assert.Equal(expected.PrincipalUniqueConstraint.Name, actual.PrincipalUniqueConstraint.Name)
- Assert.Equal(expected.PrincipalTable.SchemaQualifiedName, actual.PrincipalTable.SchemaQualifiedName)
- Assert.Contains(actual, actual.Table.ForeignKeyConstraints)
- Assert.Equal(actual.MappedForeignKeys.Select(Function(i) i.Properties.Select(Function(p) p.Name)),
- expected.MappedForeignKeys.Select(Function(i) i.Properties.Select(Function(p) p.Name)))
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IUniqueConstraint, actual As IUniqueConstraint)
- Assert.Equal(expected.Columns.Select(Function(c) c.Name), actual.Columns.Select(Function(c) c.Name))
- Assert.Equal(expected.Name, actual.Name)
- Assert.Equal(expected.GetIsPrimaryKey(), actual.GetIsPrimaryKey())
- Assert.Contains(actual, actual.Table.UniqueConstraints)
- Assert.Equal(actual.MappedKeys.Select(Function(i) i.Properties.Select(Function(p) p.Name)),
- expected.MappedKeys.Select(Function(i) i.Properties.Select(Function(p) p.Name)))
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As ITrigger, actual As ITrigger)
- Assert.Equal(expected.ModelName, actual.ModelName)
- Assert.Equal(expected.GetTableName(), actual.GetTableName())
- Assert.Equal(expected.GetTableSchema(), actual.GetTableSchema())
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IView, actual As IView)
- AssertEqualBase(expected, actual)
-
- expected.Columns.ZipAssert(actual.Columns, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.Model.FindView(actual.Name, actual.Schema))
- expected.EntityTypeMappings.ZipAssert(actual.EntityTypeMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As IViewMapping, actual As IViewMapping)
- AssertEqualBase(expected, actual)
-
- expected.ColumnMappings.ZipAssert(actual.ColumnMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As IViewColumn, actual As IViewColumn)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.View.FindColumn(actual.Name))
- End Sub
-
- Public Sub AssertEqual(expected As IViewColumnMapping, actual As IViewColumnMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.ViewMapping.ColumnMappings)
- End Sub
-
- Public Sub AssertEqual(expected As ISqlQuery, actual As ISqlQuery)
- AssertEqualBase(expected, actual)
-
- expected.Columns.ZipAssert(actual.Columns, AddressOf AssertEqual)
- Assert.Equal(expected.Sql, actual.Sql)
-
- Assert.Same(actual, actual.Model.FindQuery(actual.Name))
- expected.EntityTypeMappings.ZipAssert(actual.EntityTypeMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As ISqlQueryMapping, actual As ISqlQueryMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Equal(expected.IsDefaultSqlQueryMapping, actual.IsDefaultSqlQueryMapping)
-
- expected.ColumnMappings.ZipAssert(actual.ColumnMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As ISqlQueryColumn, actual As ISqlQueryColumn)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.SqlQuery.FindColumn(actual.Name))
- End Sub
-
- Public Sub AssertEqual(expected As ISqlQueryColumnMapping, actual As ISqlQueryColumnMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.SqlQueryMapping.ColumnMappings)
- End Sub
-
- Public Sub AssertEqual(expected As IStoreFunction, actual As IStoreFunction)
-
- AssertEqualBase(expected, actual)
-
- expected.Parameters.ZipAssert(actual.Parameters, AddressOf AssertEqual)
- expected.Columns.ZipAssert(actual.Columns, AddressOf AssertEqual)
- Assert.Equal(expected.ReturnType, actual.ReturnType)
- Assert.Equal(expected.IsBuiltIn, actual.IsBuiltIn)
-
- Assert.Same(actual, actual.Model.FindFunction(actual.Name, actual.Schema, actual.Parameters.Select(Function(p) p.StoreType).ToArray()))
- Assert.Equal(actual.DbFunctions.Select(Function(p) p.ModelName),
- expected.DbFunctions.Select(Function(p) p.ModelName))
- expected.EntityTypeMappings.ZipAssert(actual.EntityTypeMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As IFunctionMapping, actual As IFunctionMapping)
- AssertEqualBase(expected, actual)
-
- expected.ColumnMappings.ZipAssert(actual.ColumnMappings, AddressOf AssertEqual)
-
- Assert.Equal(expected.IsDefaultFunctionMapping, actual.IsDefaultFunctionMapping)
- Assert.Contains(expected.DbFunction.Name, actual.DbFunction.Name)
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IFunctionColumn, actual As IFunctionColumn)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
-
- Assert.Same(actual, actual.Function.FindColumn(actual.Name))
- End Sub
-
- Public Sub AssertEqual(expected As IFunctionColumnMapping, actual As IFunctionColumnMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.FunctionMapping.ColumnMappings)
- End Sub
-
- Public Sub AssertEqual(expected As IStoreFunctionParameter, actual As IStoreFunctionParameter)
-
- Assert.Equal(expected.Name, actual.Name)
- Assert.Equal(expected.StoreType, actual.StoreType)
- Assert.Contains(actual, actual.Function.Parameters)
- Assert.Equal(expected.DbFunctionParameters.Select(Function(p) p.Name), actual.DbFunctionParameters.Select(Function(p) p.Name))
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IStoreStoredProcedure, actual As IStoreStoredProcedure)
- AssertEqualBase(expected, actual)
-
- expected.Parameters.ZipAssert(actual.Parameters, AddressOf AssertEqual)
- expected.ResultColumns.ZipAssert(actual.ResultColumns, AddressOf AssertEqual)
-
- If expected.ReturnValue Is Nothing Then
- Assert.Null(actual.ReturnValue)
- Exit Sub
- Else
- AssertEqualBase(expected.ReturnValue, actual.ReturnValue)
- Assert.Same(actual, actual.ReturnValue.StoredProcedure)
- expected.ReturnValue.PropertyMappings.ZipAssert(actual.ReturnValue.PropertyMappings, AddressOf AssertEqual)
- End If
-
- Assert.Same(actual, actual.Model.FindStoredProcedure(actual.Name, actual.Schema))
- Assert.Equal(actual.StoredProcedures.Select(Function(p) p.Name),
- expected.StoredProcedures.Select(Function(p) p.Name))
- expected.EntityTypeMappings.ZipAssert(actual.EntityTypeMappings, AddressOf AssertEqual)
- End Sub
-
- Public Sub AssertEqual(expected As IStoredProcedureMapping, actual As IStoredProcedureMapping)
- If expected Is Nothing Then
- Assert.Null(actual)
- Exit Sub
- End If
-
- AssertEqualBase(expected, actual)
- expected.ResultColumnMappings.ZipAssert(actual.ResultColumnMappings, AddressOf AssertEqual)
- expected.ParameterMappings.ZipAssert(actual.ParameterMappings, AddressOf AssertEqual)
- Assert.Equal(expected.StoredProcedure.GetSchemaQualifiedName(), actual.StoredProcedure.GetSchemaQualifiedName())
- Assert.Equal(expected.StoreStoredProcedure.SchemaQualifiedName, actual.StoreStoredProcedure.SchemaQualifiedName)
-
- Assert.Contains(expected.TableMapping?.Table.SchemaQualifiedName, actual.TableMapping?.Table.SchemaQualifiedName)
-
- Assert.Equal(expected.GetAnnotations(), actual.GetAnnotations(), AnnotationComparer.Instance)
- Assert.Equal(expected.GetRuntimeAnnotations(), actual.GetRuntimeAnnotations(), AnnotationComparer.Instance)
- End Sub
-
- Public Sub AssertEqual(expected As IStoreStoredProcedureResultColumn, actual As IStoreStoredProcedureResultColumn)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
- Assert.Equal(expected.Position, actual.Position)
-
- Assert.Same(actual, actual.StoredProcedure.FindResultColumn(actual.Name))
- End Sub
-
- Public Sub AssertEqual(expected As IStoredProcedureResultColumnMapping, actual As IStoredProcedureResultColumnMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.StoredProcedureMapping.ResultColumnMappings)
- End Sub
-
- Public Sub AssertEqual(expected As IStoreStoredProcedureParameter, actual As IStoreStoredProcedureParameter)
- AssertEqualBase(expected, actual)
-
- expected.PropertyMappings.ZipAssert(actual.PropertyMappings, AddressOf AssertEqual)
- Assert.Equal(expected.Direction, actual.Direction)
- Assert.Equal(expected.Position, actual.Position)
-
- Assert.Same(actual, actual.StoredProcedure.FindParameter(actual.Name))
- End Sub
-
- Public Sub AssertEqual(expected As IStoredProcedureParameterMapping, actual As IStoredProcedureParameterMapping)
- AssertEqualBase(expected, actual)
-
- Assert.Contains(actual, actual.StoredProcedureMapping.ParameterMappings)
+ RelationalModelAsserter.Instance.AssertEqual(expectedModel, actualModel)
End Sub
End Module
End Namespace
diff --git a/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/TestUtilities/FakeRelationalTestHelpers.vb b/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/TestUtilities/FakeRelationalTestHelpers.vb
index 6e73394..e19f48a 100644
--- a/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/TestUtilities/FakeRelationalTestHelpers.vb
+++ b/Test/EFCore.VisualBasic.Test/TestUtilities/EFCore.Relational.Tests/TestUtilities/FakeRelationalTestHelpers.vb
@@ -15,7 +15,7 @@ Namespace TestUtilities
Public Shared ReadOnly Property Instance As FakeRelationalTestHelpers = New FakeRelationalTestHelpers
- Protected Overridable Function CreateEntityFrameworkDesignServicesBuilder(services As IServiceCollection) As EntityFrameworkDesignServicesBuilder
+ Protected Overrides Function CreateEntityFrameworkDesignServicesBuilder(services As IServiceCollection) As EntityFrameworkDesignServicesBuilder
Return New EntityFrameworkRelationalDesignServicesBuilder(services)
End Function