diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/ApplicationDbContext.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/ApplicationDbContext.cs index 30dfe075603..c65412eebbc 100644 --- a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/ApplicationDbContext.cs +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/ApplicationDbContext.cs @@ -13,70 +13,151 @@ public class ApplicationDbContext : DbContext protected override void OnModelCreating( ModelBuilder modelBuilder) { - modelBuilder.Entity( + modelBuilder.Entity( entity => { entity.HasKey(e => e.Xid) - .HasName("county_boundaries_pkey"); + .HasName("salt_lake_county_parcels_lir_pkey"); - entity.ToTable("county_boundaries", "boundaries"); + entity.ToTable("salt_lake_county_parcels_lir", "cadastre"); entity.HasIndex(e => e.Shape) - .HasName("county_boundaries_shape_geom_idx") + .HasDatabaseName("salt_lake_county_parcels_lir_shape_geom_idx") .HasMethod("gist"); entity.Property(e => e.Xid).HasColumnName("xid"); - entity.Property(e => e.Color4) - .HasColumnName("color4") - .HasColumnType("numeric(5,0)"); - - entity.Property(e => e.Countynbr) - .HasColumnName("countynbr") - .HasMaxLength(2); - - entity.Property(e => e.Entitynbr) - .HasColumnName("entitynbr") - .HasColumnType("numeric(38,8)"); + entity.Property(e => e.ParcelId) + .HasColumnName("parcel_id") + .HasMaxLength(50); - entity.Property(e => e.Entityyr) - .HasColumnName("entityyr") + entity.Property(e => e.BuildingSqFt) + .HasColumnName("bldg_sqft") .HasColumnType("numeric(38,8)"); - entity.Property(e => e.Fips) - .HasColumnName("fips") + entity.Property(e => e.Floors) + .HasColumnName("floors_cnt") .HasColumnType("numeric(38,8)"); - entity.Property(e => e.FipsStr) - .HasColumnName("fips_str") - .HasMaxLength(5); + entity.Property(e => e.RoomCount) + .HasColumnName("house_cnt") + .HasMaxLength(10); - entity.Property(e => e.Name) - .HasColumnName("name") - .HasMaxLength(100); - - entity.Property(e => e.PopCurrestimate) - .HasColumnName("pop_currestimate") - .HasColumnType("numeric(10,0)"); + entity.Property(e => e.MarketValue) + .HasColumnName("total_mkt_value") + .HasColumnType("numeric(38,8)"); - entity.Property(e => e.PopLastcensus) - .HasColumnName("pop_lastcensus") - .HasColumnType("numeric(10,0)"); + entity.Property(e => e.YearBuilt) + .HasColumnName("built_yr") + .HasColumnType("numeric(5,0)"); entity.Property(e => e.Shape) .HasColumnName("shape") .HasColumnType("geometry(MultiPolygon,26912)"); - entity.Property(e => e.Stateplane) - .HasColumnName("stateplane") - .HasMaxLength(20); - entity.Property(e => e.Shape) .HasColumnName("shape") .HasColumnType("geometry"); }); + + modelBuilder.Entity( + entity => { + entity.HasKey(e => e.Xid) + .HasName("liquor_stores_pkey"); + + entity.ToTable("liquor_stores", "society"); + + entity.HasIndex(e => e.Shape) + .HasDatabaseName("liquor_stores_shape_geom_idx") + .HasMethod("gist"); + + entity.Property(e => e.Xid).HasColumnName("xid"); + + entity.Property(e => e.Shape) + .HasColumnName("shape") + .HasColumnType("geometry"); + + entity.Property(e => e.Shape) + .HasColumnName("shape") + .HasColumnType("geometry(Point,26912)"); + + entity.Property(e => e.StoreNumber) + .HasColumnName("storenumber") + .HasColumnType("numeric(5,0)"); + + entity.Property(e => e.Zip) + .HasColumnName("zip") + .HasColumnType("numeric(10,0)"); + + entity.Property(e => e.Name) + .HasColumnName("name") + .HasMaxLength(50); + + entity.Property(e => e.Type) + .HasColumnName("type") + .HasMaxLength(20); + + entity.Property(e => e.Address) + .HasColumnName("address") + .HasMaxLength(50); + + entity.Property(e => e.City) + .HasColumnName("city") + .HasMaxLength(35); + + entity.Property(e => e.County) + .HasColumnName("county") + .HasMaxLength(25); + + entity.Property(e => e.Phone) + .HasColumnName("phone") + .HasMaxLength(15); + }); + modelBuilder.Entity( + entity => { + entity.HasKey(e => e.Xid) + .HasName("golf_courses_pkey"); + + entity.ToTable("golf_courses", "recreation"); + + entity.HasIndex(e => e.Shape) + .HasDatabaseName("golf_courses_shape_geom_idx") + .HasMethod("gist"); + + entity.Property(e => e.Xid).HasColumnName("xid"); + + entity.Property(e => e.Shape) + .HasColumnName("shape") + .HasColumnType("geometry"); + + entity.Property(e => e.Shape) + .HasColumnName("shape") + .HasColumnType("geometry(MultiPolygon,26912)"); + + entity.Property(e => e.Par) + .HasColumnName("par") + .HasColumnType("numeric(10,0)"); + + entity.Property(e => e.Holes) + .HasColumnName("holes") + .HasColumnType("numeric(10,0)"); + + entity.Property(e => e.Name) + .HasColumnName("name") + .HasMaxLength(50); + + entity.Property(e => e.City) + .HasColumnName("city") + .HasMaxLength(30); + + entity.Property(e => e.County) + .HasColumnName("county") + .HasMaxLength(30); + }); } - public DbSet Counties { get; set; } = default!; + public DbSet Parcels { get; set; } = default!; + public DbSet LiquorStores { get; set; } = default!; + public DbSet GolfCourses { get; set; } = default!; } } diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/County.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/County.cs deleted file mode 100644 index 79ba3a2ac78..00000000000 --- a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/County.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NetTopologySuite.Geometries; - -namespace Spatial.Demo -{ - public class County - { - public int Xid { get; set; } - - public string Countynbr { get; set; } - - public decimal? Entitynbr { get; set; } - - public decimal? Entityyr { get; set; } - - public string Name { get; set; } - - public decimal? Fips { get; set; } - - public string Stateplane { get; set; } - - public decimal? PopLastcensus { get; set; } - - public decimal? PopCurrestimate { get; set; } - - public string FipsStr { get; set; } - - public decimal? Color4 { get; set; } - - public MultiPolygon Shape { get; set; } - } -} diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/GolfCourse.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/GolfCourse.cs new file mode 100644 index 00000000000..04d03cfda86 --- /dev/null +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/GolfCourse.cs @@ -0,0 +1,13 @@ +using NetTopologySuite.Geometries; + +namespace Spatial.Demo { + public class GolfCourse { + public int Xid { get; set; } + public string Name { get; set; } + public string City { get; set; } + public string County { get; set; } + public int Par { get; set; } + public int Holes { get; set; } + public MultiPolygon Shape { get; set; } + } +} diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/LiquorStore.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/LiquorStore.cs new file mode 100644 index 00000000000..a82cb2c02b0 --- /dev/null +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/LiquorStore.cs @@ -0,0 +1,16 @@ +using NetTopologySuite.Geometries; + +namespace Spatial.Demo { + public class LiquorStore { + public int Xid { get; set; } + public int StoreNumber { get; set; } + public string Type { get; set; } + public string Name { get; set; } + public string Address { get; set; } + public string City { get; set; } + public string County { get; set; } + public string Phone { get; set; } + public int Zip { get; set; } + public Point Shape { get; set; } + } +} diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/Parcel.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/Parcel.cs new file mode 100644 index 00000000000..ff21ed46055 --- /dev/null +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Database/Parcel.cs @@ -0,0 +1,16 @@ +using NetTopologySuite.Geometries; + +namespace Spatial.Demo +{ + public class Parcel + { + public int Xid { get; set; } + public string ParcelId { get; set; } + public int BuildingSqFt { get; set; } + public int Floors { get; set; } + public string RoomCount { get; set; } + public decimal? MarketValue { get; set; } + public int YearBuilt { get; set; } + public MultiPolygon Shape { get; set; } + } +} diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Schema/Query.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Schema/Query.cs index 8a1ca6ff9a0..2086f385cc4 100644 --- a/src/HotChocolate/Spatial/demo/Spatial.Demo/Schema/Query.cs +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Schema/Query.cs @@ -7,9 +7,24 @@ namespace Spatial.Demo public class Query { [UseDbContext(typeof(ApplicationDbContext))] + [UseProjection] [UseFiltering] - public IQueryable GetCounties( + public IQueryable GetParcels( [ScopedService] ApplicationDbContext context) => - context.Counties; + context.Parcels; + + [UseDbContext(typeof(ApplicationDbContext))] + [UseProjection] + [UseFiltering] + public IQueryable GetLiquorStores( + [ScopedService] ApplicationDbContext context) => + context.LiquorStores; + + [UseDbContext(typeof(ApplicationDbContext))] + [UseProjection] + [UseFiltering] + public IQueryable GetGolfCourses( + [ScopedService] ApplicationDbContext context) => + context.GolfCourses; } } diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Spatial.Demo.csproj b/src/HotChocolate/Spatial/demo/Spatial.Demo/Spatial.Demo.csproj index 5b291111370..4fe6c6e2fd4 100644 --- a/src/HotChocolate/Spatial/demo/Spatial.Demo/Spatial.Demo.csproj +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Spatial.Demo.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/src/HotChocolate/Spatial/demo/Spatial.Demo/Startup.cs b/src/HotChocolate/Spatial/demo/Spatial.Demo/Startup.cs index 69bcf249854..83a13c37bec 100644 --- a/src/HotChocolate/Spatial/demo/Spatial.Demo/Startup.cs +++ b/src/HotChocolate/Spatial/demo/Spatial.Demo/Startup.cs @@ -1,44 +1,30 @@ +using System; using HotChocolate; -using HotChocolate.Data.Filters; -using HotChocolate.Data.Filters.Expressions; -using HotChocolate.Data.Filters; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; namespace Spatial.Demo { public class Startup { - public static readonly ILoggerFactory loggerFactory = - LoggerFactory.Create(x => x.AddConsole()); - - private const string connectionString = + private const string CONNECTION_STRING = "Database=opensgid;Host=opensgid.agrc.utah.gov;Username=agrc;Password=agrc"; public void ConfigureServices(IServiceCollection services) { - services.AddDbContextPool( - options => - options.UseNpgsql( - connectionString, - o => - o.UseNetTopologySuite()) - .UseLoggerFactory(loggerFactory) - ) + services.AddPooledDbContextFactory( + options => options + .UseNpgsql(CONNECTION_STRING, o => o.UseNetTopologySuite()) + .LogTo(Console.WriteLine)) .AddGraphQLServer() + .AddFiltering() + .AddProjections() .AddSpatialTypes() - .AddFiltering( - x => x - .AddDefaults() - .AddSpatialOperations() - .BindSpatialTypes() - .Provider( - new QueryableFilterProvider( - p => p.AddSpatialHandlers().AddDefaultFieldHandlers()))) + .AddSpatialProjections() + .AddSpatialFiltering() .AddQueryType(); }