Skip to content

Commit

Permalink
Merge branch 'master' into bug/551-Connectionstring
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 authored Mar 22, 2024
2 parents bf7fe40 + 23af8b9 commit 1b981f6
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 54 deletions.
2 changes: 1 addition & 1 deletion sample/Tracker/Tracker.Core/Tracker.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="Injectio" Version="3.1.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
</ItemGroup>

</Project>
5 changes: 2 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
<PropertyGroup>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AssemblyMetadata.Generators" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="5.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,24 +444,28 @@ private void ConfigureMySqlServices(IServiceCollection services)
{
var designTimeServices = new Pomelo.EntityFrameworkCore.MySql.Design.Internal.MySqlDesignTimeServices();
designTimeServices.ConfigureDesignTimeServices(services);
services.AddEntityFrameworkMySqlNetTopologySuite();
}

private void ConfigurePostgresServices(IServiceCollection services)
{
var designTimeServices = new Npgsql.EntityFrameworkCore.PostgreSQL.Design.Internal.NpgsqlDesignTimeServices();
designTimeServices.ConfigureDesignTimeServices(services);
services.AddEntityFrameworkNpgsqlNetTopologySuite();
}

private void ConfigureSqlServerServices(IServiceCollection services)
{
var designTimeServices = new Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerDesignTimeServices();
designTimeServices.ConfigureDesignTimeServices(services);
services.AddEntityFrameworkSqlServerNetTopologySuite();
}

private void ConfigureSqliteServices(IServiceCollection services)
{
var designTimeServices = new Microsoft.EntityFrameworkCore.Sqlite.Design.Internal.SqliteDesignTimeServices();
designTimeServices.ConfigureDesignTimeServices(services);
services.AddEntityFrameworkSqliteNetTopologySuite();
}

private void ConfigureOracleServices(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>EntityFrameworkCore.Generator</RootNamespace>
Expand All @@ -7,15 +7,19 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="8.21.121" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" />
<PackageReference Include="YamlDotNet" Version="15.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="YamlDotNet" Version="15.1.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,6 @@ public EntityClassOptions(VariableDictionary variables, string prefix)
Renaming = new SelectionOptions(variables, AppendPrefix(prefix, "Naming"));
}

/// <summary>
/// Gets or sets the entity class name template.
/// </summary>
/// <value>
/// The entity class name template.
/// </value>
public string Name
{
get => GetProperty();
set => SetProperty(value);
}

/// <summary>
/// Gets or sets the base class to inherit from.
/// </summary>
/// <value>
/// The base class.
/// </value>
public string BaseClass
{
get => GetProperty();
set => SetProperty(value);
}

/// <summary>
/// Gets or sets the entity class naming strategy.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ public EntityClass()
PrefixWithSchemaName = false;
}

/// <summary>
/// Gets or sets the entity class name template.
/// </summary>
/// <value>
/// The entity class name template.
/// </value>
public string Name { get; set; }

/// <summary>
/// Gets or sets the base class to inherit from.
/// </summary>
/// <value>
/// The base class.
/// </value>
public string BaseClass { get; set; }

/// <summary>
/// Gets or sets the entity class naming strategy.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions;
using FluentCommand.SqlServer.Tests;
using Microsoft.Extensions.Logging.Abstractions;
using System.IO;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -26,6 +27,7 @@ public void Generate()
result.Should().BeTrue();
}


[Fact]
public void Generate_Should_Work_For_Password_With_CurlyBrace()
{
Expand All @@ -38,4 +40,39 @@ public void Generate_Should_Work_For_Password_With_CurlyBrace()

result.Should().BeTrue();
}
[Fact]
public void GenerateSpatial()
{
var generatorOptions = new GeneratorOptions();
generatorOptions.Database.ConnectionString = Database.ConnectionString;

var generator = new CodeGenerator(NullLoggerFactory.Instance);
var result = generator.Generate(generatorOptions);

result.Should().BeTrue();

const string spatialTableName = "CitiesSpatial";

var citiesSpatialEntityFile = Path.Combine(generatorOptions.Data.Entity.Directory, spatialTableName + ".cs");
var citiesSpatialMappingFile = Path.Combine(generatorOptions.Data.Mapping.Directory, spatialTableName + "Map.cs");

var citiesSpatialEntityContent = File.ReadAllText(citiesSpatialEntityFile);
var citiesSpatialMappingContent = File.ReadAllText(citiesSpatialMappingFile);

citiesSpatialEntityContent.Contains("public NetTopologySuite.Geometries.Geometry GeometryField { get; set; }").Should().BeTrue();
citiesSpatialEntityContent.Contains("public NetTopologySuite.Geometries.Geometry GeographyField { get; set; }").Should().BeTrue();

citiesSpatialMappingContent.Contains("builder.Property(t => t.GeometryField)" + System.Environment.NewLine +
" .IsRequired()" + System.Environment.NewLine +
" .HasColumnName(\"GeometryField\")" + System.Environment.NewLine +
" .HasColumnType(\"geometry\");").Should().BeTrue();

citiesSpatialMappingContent.Contains("builder.Property(t => t.GeographyField)" + System.Environment.NewLine +
" .IsRequired()" + System.Environment.NewLine +
" .HasColumnName(\"GeographyField\")" + System.Environment.NewLine +
" .HasColumnType(\"geography\");").Should().BeTrue();

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<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 @@ -142,6 +142,14 @@ CREATE TABLE [dbo].[UserRole] (
CONSTRAINT [PK_UserRole] PRIMARY KEY ([UserId], [RoleId])
);

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CitiesSpatial]') AND type in (N'U'))
CREATE TABLE [dbo].[CitiesSpatial](
[Id] int IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[GeometryField] [geometry] NOT NULL,
[GeographyField] [geography] NOT NULL,
CONSTRAINT [PK_CitiesSpatial] PRIMARY KEY ([Id])
)

-- Foreign Keys
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Task_Priority_PriorityId]') AND parent_object_id = OBJECT_ID(N'[dbo].[Task]'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ WHEN MATCHED THEN
UPDATE SET t.[Name] = s.[Name], t.[Description] = s.[Description]
OUTPUT $action as [Action];

-- Table [dbo].[CitiesSpatial] data

INSERT INTO [dbo].[CitiesSpatial] VALUES
('Sydney', 'POINT(151.2 -33.8)', 'POINT(151.2 -33.8)'),
('Athens', 'POINT(23.7 38)', 'POINT(23.7 38)'),
('Beijing', 'POINT(116.4 39.9)', 'POINT(116.4 39.9)'),
('London', 'POINT(-0.15 51.5)', 'POINT(-0.15 51.5)');

0 comments on commit 1b981f6

Please sign in to comment.