Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Test
run: >-
dotnet test --solution EntityFrameworkCore.Extensions.sln
--configuration Release --no-build --minimum-expected-tests 35
--configuration Release --no-build

sqlserver-integration:
name: SQL Server integration
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Test against SQL Server
run: >-
dotnet test --solution EntityFrameworkCore.Extensions.sln
--configuration Release --no-build --minimum-expected-tests 35 --fail-skips on
--configuration Release --no-build --fail-skips on

package:
name: Validate package
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Test against SQL Server
run: >-
dotnet test --solution EntityFrameworkCore.Extensions.sln
--configuration Release --no-build --minimum-expected-tests 35 --fail-skips on
--configuration Release --no-build --fail-skips on
- name: Pack
run: >-
dotnet pack EntityFrameworkCore.Extensions/EntityFrameworkCore.Extensions.csproj
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="[10.0.11,11.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="[10.0.11,11.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="[10.0.11,11.0.0)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="[10.0.11,11.0.0)" />
<PackageVersion Include="xunit.v3" Version="4.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" />
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore.Migrations;
using NetTopologySuite.Geometries;

#nullable disable

namespace EntityFrameworkCore.Extensions.Samples.Migrations
{
/// <inheritdoc />
public partial class AddSpatialIndexes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Places",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Location = table.Column<Point>(type: "geography", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Places", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Regions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Boundary = table.Column<Polygon>(type: "geometry", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Regions", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "SIX_Places_Location",
table: "Places",
column: "Location")
.Annotation("EntityFrameworkCore.Extensions:SpatialIndex", true)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexType", "geography");

migrationBuilder.CreateIndex(
name: "SIX_Regions_Boundary",
table: "Regions",
column: "Boundary")
.Annotation("EntityFrameworkCore.Extensions:SpatialIndex", true)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxXMax", 180.0)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxXMin", -180.0)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxYMax", 90.0)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxYMin", -90.0)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexCellsPerObject", 32)
.Annotation("EntityFrameworkCore.Extensions:SpatialIndexType", "geometry");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Places");

migrationBuilder.DropTable(
name: "Regions");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NetTopologySuite.Geometries;

#nullable disable

Expand Down Expand Up @@ -86,6 +87,53 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Order");
});

modelBuilder.Entity("EntityFrameworkCore.Extensions.Samples.Place", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<Point>("Location")
.IsRequired()
.HasColumnType("geography");

b.HasKey("Id");

b.HasIndex("Location")
.HasDatabaseName("SIX_Places_Location")
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndex", true);

b.ToTable("Places");
});

modelBuilder.Entity("EntityFrameworkCore.Extensions.Samples.Region", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<Polygon>("Boundary")
.IsRequired()
.HasColumnType("geometry");

b.HasKey("Id");

b.HasIndex("Boundary")
.HasDatabaseName("SIX_Regions_Boundary")
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndex", true)
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxXMax", 180.0)
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxXMin", -180.0)
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxYMax", 90.0)
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndexBoundingBoxYMin", -90.0)
.HasAnnotation("EntityFrameworkCore.Extensions:SpatialIndexCellsPerObject", 32);

b.ToTable("Regions");
});

modelBuilder.Entity("EntityFrameworkCore.Extensions.Samples.Order", b =>
{
b.HasOne("EntityFrameworkCore.Extensions.Samples.Customer", null)
Expand Down
14 changes: 14 additions & 0 deletions EntityFrameworkCore.Extensions.Samples/Models.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using NetTopologySuite.Geometries;

namespace EntityFrameworkCore.Extensions.Samples;

public class Customer
Expand All @@ -19,3 +21,15 @@ public class Order
public int Id { get; set; }
public DateTime Created { get; set; }
}

public class Place
{
public int Id { get; set; }
public Point Location { get; set; } = new(0, 0) { SRID = 4326 };
}

public class Region
{
public int Id { get; set; }
public Polygon Boundary { get; set; } = null!;
}
19 changes: 18 additions & 1 deletion EntityFrameworkCore.Extensions.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ internal sealed class Program
public sealed class SampleContext : DbContext
{
public DbSet<Customer> Customers => Set<Customer>();
public DbSet<Place> Places => Set<Place>();
public DbSet<Region> Regions => Set<Region>();

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(
"Data Source=.;Initial Catalog=EntityFrameworkCoreExtensionsSamples;Integrated Security=True;TrustServerCertificate=True");
"Data Source=.;Initial Catalog=EntityFrameworkCoreExtensionsSamples;Integrated Security=True;TrustServerCertificate=True",
sqlServer => sqlServer.UseNetTopologySuite());
}

optionsBuilder.UseEntityFrameworkCoreExtensions();
Expand All @@ -26,6 +29,20 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Customer>().Property(customer => customer.Surname).HasDataMask(MaskingFunctions.Default());
modelBuilder.Entity<Customer>().Property(customer => customer.DiscountCardNumber).HasDataMask(MaskingFunctions.Random(10, 100));
modelBuilder.Entity<Customer>().Property(customer => customer.Phone).HasDataMask(MaskingFunctions.Partial(2, "XX-XX", 1));

modelBuilder.Entity<Place>().Property(place => place.Location).HasColumnType("geography");
modelBuilder.Entity<Place>()
.HasSpatialIndex(place => place.Location)
.HasDatabaseName("SIX_Places_Location");

modelBuilder.Entity<Region>().Property(region => region.Boundary).HasColumnType("geometry");
modelBuilder.Entity<Region>()
.HasSpatialIndex(
region => region.Boundary,
spatial => spatial
.HasBoundingBox(-180, -90, 180, 90)
.HasCellsPerObject(32))
.HasDatabaseName("SIX_Regions_Boundary");
}
}

Expand Down
Loading