Skip to content

Commit

Permalink
Some code cleanup
Browse files Browse the repository at this point in the history
* update dependencies
  • Loading branch information
lorcQc authored Oct 4, 2022
1 parent 4ca792c commit dc6b681
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 51 deletions.
24 changes: 13 additions & 11 deletions EFCore.VisualBasic/Design/Internal/VisualBasicHelper.vb
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,10 @@ Namespace Design.Internal
Append(Reference(type)).
Append(")"c)

Return HandleEnumerable(builder, vertical, values, Sub(value)
builder.Append(UnknownLiteral(value))
End Sub)
Return HandleEnumerable(
builder, vertical, values, Sub(value)
builder.Append(UnknownLiteral(value))
End Sub)
End Function

''' <summary>
Expand All @@ -631,14 +632,15 @@ Namespace Design.Internal
Append(Reference(valueType)).
Append(")")

Return HandleEnumerable(builder, vertical, dict.Keys, Sub(key)
builder.
Append("{").
Append(UnknownLiteral(key)).
Append(", ").
Append(UnknownLiteral(dict(key))).
Append("}")
End Sub)
Return HandleEnumerable(
builder, vertical, dict.Keys, Sub(key)
builder.
Append("{").
Append(UnknownLiteral(key)).
Append(", ").
Append(UnknownLiteral(dict(key))).
Append("}")
End Sub)
End Function

Private Shared Function HandleEnumerable(builder As IndentedStringBuilder, vertical As Boolean, values As IEnumerable, handleValue As Action(Of Object)) As String
Expand Down
8 changes: 4 additions & 4 deletions EFCore.VisualBasic/EFCore.VisualBasic.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="7.0.0-rc.2.22457.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="7.0.0-rtm.22501.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-rc.2.22457.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-rtm.22501.1">
<IncludeAssets>all</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0-rc.2.22457.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0-rtm.22501.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-rc.2.22457.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-rtm.22501.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion EFCore.VisualBasic/Multigraph.vb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Namespace Utilities
' TODO: Optimization : Instead of currentBatchSet, store a batch counter On Each vertex, And check if later
' vertexes have a boundary-requiring dependency on a vertex with the same batch counter.
If withBatching AndAlso
_predecessorMap(successor).Any(
_predecessorMap(successor).Any(
Function(kv)

If TypeOf kv.Value Is Edge Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ $" Dim model As New {className}()
prop.DeclaringEntityType.ShortName(), prop.Name, NameOf(PropertyBuilder.HasConversion)))
End If

Dim valueConverterType = TryCast(prop(CoreAnnotationNames.ValueConverterType), Type)
Dim valueConverterType = GetValueConverterType(prop)

If valueConverterType Is Nothing AndAlso
prop.GetValueConverter() IsNot Nothing Then
Expand Down Expand Up @@ -873,6 +873,39 @@ $" Dim model As New {className}()
AppendLine()
End Sub

Private Shared Function GetValueConverterType(prop As IProperty) As Type
Dim type = TryCast(prop(CoreAnnotationNames.ValueConverterType), Type)

If type IsNot Nothing Then
Return type
End If

Dim principalProperty = prop
For i = 0 To 10000 - 1
For Each foreignKey In principalProperty.GetContainingForeignKeys()
For propertyIndex = 0 To foreignKey.Properties.Count - 1
If principalProperty Is foreignKey.Properties(propertyIndex) Then
Dim newPrincipalProperty = foreignKey.PrincipalKey.Properties(propertyIndex)
If prop Is principalProperty OrElse
newPrincipalProperty Is principalProperty Then

Exit For
End If

principalProperty = newPrincipalProperty

type = TryCast(principalProperty(CoreAnnotationNames.ValueConverterType), Type)
If type IsNot Nothing Then
Return type
End If
End If
Next
Next
Next

Return Nothing
End Function

Private Sub PropertyBaseParameters(Prop As IPropertyBase,
parameters As VisualBasicRuntimeAnnotationCodeGeneratorParameters,
Optional skipType As Boolean = False)
Expand Down
8 changes: 4 additions & 4 deletions Sandbox/Sandbox.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0-rc.2.22457.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0-rtm.22501.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="7.0.0-rtm.22501.1" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions Test/EFCore.VisualBasic.Test/EFCore.VisualBasic.Test.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-rc.2.22457.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-rtm.22501.1">
<IncludeAssets>all</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Specification.Tests" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-rc.2.22457.11" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0-rc.2.22456.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Specification.Tests" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0-rtm.22501.1" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0-rtm.22480.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0-preview-20220726-02" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.console" Version="2.4.2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ End Namespace
IncrementsBy(2).
HasMin(2).
HasMax(100).
IsCyclic(True)
IsCyclic()
End Sub,
New ModelCodeGenerationOptions(),
Sub(code)
Expand Down Expand Up @@ -1378,7 +1378,8 @@ End Namespace
Dim EntityType = Model.FindEntityType("TestNamespace.Employee")
Dim triggers = EntityType.GetDeclaredTriggers()

Assert.Collection(triggers,
Assert.Collection(
triggers,
Sub(t) Assert.Equal("Trigger1", t.GetDatabaseName),
Sub(t) Assert.Equal("Trigger2", t.GetDatabaseName))
End Sub)
Expand Down Expand Up @@ -1448,6 +1449,27 @@ End Namespace
End Sub)
End Sub

<ConditionalTheory>
<InlineData(False)>
<InlineData(True)>
Public Sub ColumnOrder_is_ignored(useDataAnnotations As Boolean)
Test(
Sub(ModelBuilder)
ModelBuilder.Entity("Entity").Property(Of String)("Property").HasColumnOrder(1)
End Sub,
New ModelCodeGenerationOptions With {
.UseDataAnnotations = useDataAnnotations
},
Sub(code)
Assert.DoesNotContain(".HasColumnOrder(1)", code.ContextFile.Code)
Assert.DoesNotContain("[Column(Order = 1)]", code.AdditionalFiles(0).Code)
End Sub,
Sub(Model)
Dim entity = Model.FindEntityType("TestNamespace.Entity")
Assert.Null(entity.GetProperty("Property").GetColumnOrder())
End Sub)
End Sub

Protected Overrides Sub AddModelServices(services As IServiceCollection)
services.Replace(ServiceDescriptor.Singleton(Of IRelationalAnnotationProvider, TestModelAnnotationProvider)())
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Namespace Global
End Namespace

Namespace Scaffolding.Internal

Public Class VisualBasicRuntimeModelCodeGeneratorTest

<ConditionalFact>
Expand Down Expand Up @@ -256,7 +255,7 @@ End Namespace
Public Overridable Property ReferenceNavigation As LazyProxiesEntity2
End Class

Public Class LazyProxiesEntity2
Public Class LazyProxiesEntity2
Public Property Loader As ILazyLoader

Public Property Id As Integer
Expand Down Expand Up @@ -2542,7 +2541,7 @@ Namespace TestNamespace
True)

Dim id0 = deleteSproc.AddParameter(
"Id", ParameterDirection.Input, False, "Id", False)
"Id_Original", ParameterDirection.Input, False, "Id", True)
entityType.AddAnnotation("Relational:DeleteStoredProcedure", deleteSproc)

Dim updateSproc As New RuntimeStoredProcedure(
Expand All @@ -2556,7 +2555,7 @@ Namespace TestNamespace
Dim principalDerivedId0 = updateSproc.AddParameter(
"PrincipalDerivedId", ParameterDirection.Input, False, "PrincipalDerivedId", False)
Dim id1 = updateSproc.AddParameter(
"Id", ParameterDirection.Input, False, "Id", False)
"Id_Original", ParameterDirection.Input, False, "Id", True)
entityType.AddAnnotation("Relational:UpdateStoredProcedure", updateSproc)

entityType.AddAnnotation("Relational:FunctionName", Nothing)
Expand Down Expand Up @@ -2621,7 +2620,7 @@ Namespace TestNamespace
False)

Dim id = deleteSproc.AddParameter(
"Id", ParameterDirection.Input, False, "Id", False)
"Id_Original", ParameterDirection.Input, False, "Id", True)
entityType.AddAnnotation("Relational:DeleteStoredProcedure", deleteSproc)

Dim updateSproc As New RuntimeStoredProcedure(
Expand All @@ -2635,7 +2634,7 @@ Namespace TestNamespace
Dim principalDerivedId0 = updateSproc.AddParameter(
"PrincipalDerivedId", ParameterDirection.Input, False, "PrincipalDerivedId", False)
Dim id0 = updateSproc.AddParameter(
"Id", ParameterDirection.Input, False, "Id", False)
"Id_Original", ParameterDirection.Input, False, "Id", True)
entityType.AddAnnotation("Relational:UpdateStoredProcedure", updateSproc)

entityType.AddAnnotation("Relational:FunctionName", Nothing)
Expand Down Expand Up @@ -2748,17 +2747,17 @@ End Namespace
Assert.False(updateSproc.IsRowsAffectedReturned)
Assert.Empty(updateSproc.GetAnnotations())
Assert.Same(PrincipalBase, updateSproc.EntityType)
Assert.Equal("Id", updateSproc.Parameters.Last().Name)
Assert.Equal("Id_Original", updateSproc.Parameters.Last().Name)
Assert.Null(id.FindOverrides(StoreObjectIdentifier.Create(PrincipalBase, StoreObjectType.UpdateStoredProcedure).Value))

Dim deleteSproc = PrincipalBase.GetDeleteStoredProcedure()
Assert.Equal("PrincipalBase_Delete", deleteSproc.Name)
Assert.Equal("TPC", deleteSproc.Schema)
Assert.Equal({"Id"}, deleteSproc.Parameters.Select(Function(p) p.PropertyName))
Assert.Equal({"Id_Original"}, deleteSproc.Parameters.Select(Function(p) p.Name))
Assert.Empty(deleteSproc.ResultColumns)
Assert.True(deleteSproc.IsRowsAffectedReturned)
Assert.Same(PrincipalBase, deleteSproc.EntityType)
Assert.Equal("Id", deleteSproc.Parameters.Last().Name)
Assert.Equal("Id_Original", deleteSproc.Parameters.Last().Name)
Assert.Null(id.FindOverrides(StoreObjectIdentifier.Create(PrincipalBase, StoreObjectType.DeleteStoredProcedure).Value))

Assert.Equal("PrincipalBase", PrincipalBase.GetDiscriminatorValue())
Expand Down Expand Up @@ -2804,7 +2803,7 @@ End Namespace
Assert.Empty(updateSproc.ResultColumns)
Assert.Empty(updateSproc.GetAnnotations())
Assert.Same(PrincipalDerived, updateSproc.EntityType)
Assert.Equal("Id", updateSproc.Parameters.Last().Name)
Assert.Equal("Id_Original", updateSproc.Parameters.Last().Name)
Assert.Null(
id.FindOverrides(StoreObjectIdentifier.Create(PrincipalDerived, StoreObjectType.UpdateStoredProcedure).Value))

Expand All @@ -2814,7 +2813,7 @@ End Namespace
Assert.Equal({"Id"}, deleteSproc.Parameters.Select(Function(p) p.PropertyName))
Assert.Empty(deleteSproc.ResultColumns)
Assert.Same(PrincipalDerived, deleteSproc.EntityType)
Assert.Equal("Id", deleteSproc.Parameters.Last().Name)
Assert.Equal("Id_Original", deleteSproc.Parameters.Last().Name)
Assert.Null(
id.FindOverrides(StoreObjectIdentifier.Create(PrincipalDerived, StoreObjectType.DeleteStoredProcedure).Value))

Expand Down Expand Up @@ -2900,10 +2899,11 @@ End Namespace
eb.UpdateUsingStoredProcedure(Sub(s) s.
HasParameter("PrincipalBaseId").
HasParameter("PrincipalDerivedId").
HasParameter(Function(p) p.Id))
HasOriginalValueParameter(Function(p) p.Id))
eb.DeleteUsingStoredProcedure(Sub(s) s.
HasRowsAffectedReturnValue().
HasParameter(Function(p) p.Id))
HasOriginalValueParameter(Function(p) p.Id))

eb.HasIndex({"PrincipalBaseId"}, "PrincipalIndex").
IsUnique().
HasDatabaseName("PIX").
Expand Down Expand Up @@ -2932,9 +2932,9 @@ End Namespace
eb.UpdateUsingStoredProcedure("Derived_Update", "Derived", Sub(s) s.
HasParameter("PrincipalBaseId").
HasParameter("PrincipalDerivedId").
HasParameter(Function(p) p.Id))
HasOriginalValueParameter(Function(p) p.Id))
eb.DeleteUsingStoredProcedure("Derived_Delete", Sub(s) s.
HasParameter(Function(p) p.Id))
HasOriginalValueParameter(Function(p) p.Id))
End Sub)

modelBuilder.Entity(Of DependentBase(Of Byte?))(
Expand Down Expand Up @@ -4198,7 +4198,7 @@ End Namespace
End Class

<ConditionalFact>
Public Sub Sqlite()
Public Sub Sqlite()

Dim rm1 =
<![CDATA[' <auto-generated />
Expand Down Expand Up @@ -4870,7 +4870,7 @@ Namespace Scaffolding.TestModel.Internal
Sub(eb)
eb.Property(Function(e) e.Collection).HasConversion(GetType(SelfReferentialPropertyValueConverter))
End Sub)
End sub
End Sub
End Class

Public Class SelfReferentialPropertyValueConverter
Expand Down

0 comments on commit dc6b681

Please sign in to comment.