diff --git a/sample/Tracker/Tracker.Core/Tracker.Core.csproj b/sample/Tracker/Tracker.Core/Tracker.Core.csproj index 4d75eac8..9c20898d 100644 --- a/sample/Tracker/Tracker.Core/Tracker.Core.csproj +++ b/sample/Tracker/Tracker.Core/Tracker.Core.csproj @@ -10,7 +10,7 @@ - + diff --git a/sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj b/sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj index f2611049..d9562bb3 100644 --- a/sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj +++ b/sample/Tracker/Tracker.Scaffold/Tracker.Scaffold.csproj @@ -8,11 +8,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 795e7eca..b9154d86 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -32,11 +32,10 @@ v - + - - + diff --git a/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs b/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs index 682482bd..e0aa082d 100644 --- a/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs +++ b/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs @@ -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) diff --git a/src/EntityFrameworkCore.Generator.Core/EntityFrameworkCore.Generator.Core.csproj b/src/EntityFrameworkCore.Generator.Core/EntityFrameworkCore.Generator.Core.csproj index ff5dafee..27852be9 100644 --- a/src/EntityFrameworkCore.Generator.Core/EntityFrameworkCore.Generator.Core.csproj +++ b/src/EntityFrameworkCore.Generator.Core/EntityFrameworkCore.Generator.Core.csproj @@ -1,4 +1,4 @@ - + net8.0 EntityFrameworkCore.Generator @@ -7,15 +7,19 @@ + + - - - - + + + + + + - - + + diff --git a/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs b/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs index 3878ce7a..bcd70548 100644 --- a/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs +++ b/src/EntityFrameworkCore.Generator.Core/Options/EntityClassOptions.cs @@ -24,30 +24,6 @@ public EntityClassOptions(VariableDictionary variables, string prefix) Renaming = new SelectionOptions(variables, AppendPrefix(prefix, "Naming")); } - /// - /// Gets or sets the entity class name template. - /// - /// - /// The entity class name template. - /// - public string Name - { - get => GetProperty(); - set => SetProperty(value); - } - - /// - /// Gets or sets the base class to inherit from. - /// - /// - /// The base class. - /// - public string BaseClass - { - get => GetProperty(); - set => SetProperty(value); - } - /// /// Gets or sets the entity class naming strategy. /// diff --git a/src/EntityFrameworkCore.Generator.Core/Serialization/EntityClass.cs b/src/EntityFrameworkCore.Generator.Core/Serialization/EntityClass.cs index 44df5285..1ca37afb 100644 --- a/src/EntityFrameworkCore.Generator.Core/Serialization/EntityClass.cs +++ b/src/EntityFrameworkCore.Generator.Core/Serialization/EntityClass.cs @@ -23,22 +23,6 @@ public EntityClass() PrefixWithSchemaName = false; } - /// - /// Gets or sets the entity class name template. - /// - /// - /// The entity class name template. - /// - public string Name { get; set; } - - /// - /// Gets or sets the base class to inherit from. - /// - /// - /// The base class. - /// - public string BaseClass { get; set; } - /// /// Gets or sets the entity class naming strategy. /// diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs b/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs index c87b0dcf..c83c78d2 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs +++ b/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs @@ -2,6 +2,7 @@ using FluentAssertions; using FluentCommand.SqlServer.Tests; using Microsoft.Extensions.Logging.Abstractions; +using System.IO; using Xunit; using Xunit.Abstractions; @@ -26,6 +27,7 @@ public void Generate() result.Should().BeTrue(); } + [Fact] public void Generate_Should_Work_For_Password_With_CurlyBrace() { @@ -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(); + + } + } + diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj b/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj index 26f0ac9c..397eb1e2 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj +++ b/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script001.Tracker.Schema.sql b/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script001.Tracker.Schema.sql index a69ce25e..48960ca3 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script001.Tracker.Schema.sql +++ b/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script001.Tracker.Schema.sql @@ -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]')) diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script002.Tracker.Data.sql b/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script002.Tracker.Data.sql index c6bd2cf1..00b466ff 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script002.Tracker.Data.sql +++ b/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script002.Tracker.Data.sql @@ -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)'); \ No newline at end of file