diff --git a/Src/Asp.NetCore2/PgSqlTest/Program.cs b/Src/Asp.NetCore2/PgSqlTest/Program.cs index bb4b99e75..095f32bdb 100644 --- a/Src/Asp.NetCore2/PgSqlTest/Program.cs +++ b/Src/Asp.NetCore2/PgSqlTest/Program.cs @@ -23,12 +23,13 @@ namespace OrmTest _9_Update.Init(); _a1_Delete.Init(); _a2_Sql.Init(); - _a3_Merge.Init(); + _a3_Merge.Init(); _a4_SplitTable.Init(); _a5_GridSave.Init(); _a6_SqlPage.Init(); _a7_JsonType.Init(); _a8_SelectReturnType.Init(); + _a9_GeometryTest.Init(); } } @@ -57,7 +58,6 @@ namespace OrmTest DbType = DbType.PostgreSQL, ConnectionString = Connection, LanguageType=LanguageType.Default//Set language - }, it => { // Logging SQL statements and parameters before execution diff --git a/Src/Asp.NetCore2/PgSqlTest/a9_GeometryTest.cs b/Src/Asp.NetCore2/PgSqlTest/a9_GeometryTest.cs new file mode 100644 index 000000000..b00689140 --- /dev/null +++ b/Src/Asp.NetCore2/PgSqlTest/a9_GeometryTest.cs @@ -0,0 +1,126 @@ +using NpgsqlTypes; +using SqlSugar; + +namespace OrmTest; + +public class _a9_GeometryTest +{ + public static void Init() + { + // Get a new database instance + // 获取新的数据库实例 + var db = DbHelper.GetNewDb(); + + // Create the database if it doesn't exist + // 如果数据库不存在,则创建数据库 + db.DbMaintenance.CreateDatabase(); + + // Initialize tables based on G1 entity class + // 根据 G1 实体类初始化表 + db.CodeFirst.InitTables(); + + //Prepare data + //准备数据 + var points = new NpgsqlPoint[] + { + new NpgsqlPoint(0,-10), + new NpgsqlPoint(7,-7), + new NpgsqlPoint(10,0), + new NpgsqlPoint(7,7), + new NpgsqlPoint(0,10), + new NpgsqlPoint(-7,7), + new NpgsqlPoint(-10,0), + new NpgsqlPoint(-7,-7), + }; + + //Insert + //插入 + var id = db.Insertable(new Geometries + { + Box = new NpgsqlBox(5, 4, 0, 0), + Circle = new NpgsqlCircle(4, 5, 3), + Line = new NpgsqlLine(1, 2, 3), + Lseg = new NpgsqlLSeg(1, 2, 3, 4), + Path = new NpgsqlPath(points), + Point = new NpgsqlPoint(0, 1), + Polygon = new NpgsqlPolygon(points), + }).ExecuteReturnIdentity(); + + //Query + //查询 + var geom = db.Queryable().InSingle(id); + + var container = db.Queryable() + .Where($"@point <@ {nameof(Geometries.Polygon)}", new { point = new NpgsqlPoint(3, 4) }) + .First(); + + var area = db.Queryable() + .Select($"area({nameof(Geometries.Circle)})") + .First(); + + var length = db.Queryable() + .Select($"@-@ {nameof(Geometries.Path)}") + .First(); + + var center = db.Queryable() + .Select($"@@ {nameof(Geometries.Box)}") + .First(); + + //Update + //更新 + db.Updateable(geom).ExecuteCommand(); + + //Delete + //删除 + db.Deleteable(geom).ExecuteCommand(); + } +} + +/// +/// Geometry entity class +/// 几何实体类 +/// +public class Geometries +{ + /// + /// ID (Primary Key) + /// ID(主键) + /// + [SugarColumn(IsIdentity = true, IsPrimaryKey = true)] + public int Id { get; set; } + + /// + /// 矩形框 + /// + public NpgsqlBox Box { get; set; } + + /// + /// 圆 + /// + public NpgsqlCircle Circle { get; set; } + + /// + /// 线 Ax + By + C = 0 + /// + public NpgsqlLine Line { get; set; } + + /// + /// 线段 + /// + public NpgsqlLSeg Lseg { get; set; } + + /// + /// 路径 + /// + public NpgsqlPath Path { get; set; } + + /// + /// 坐标点 + /// + public NpgsqlPoint Point { get; set; } + + /// + /// 多边形 + /// + public NpgsqlPolygon Polygon { get; set; } +} \ No newline at end of file diff --git a/Src/Asp.NetCore2/SqlSugar/Enum/ProperyType.cs b/Src/Asp.NetCore2/SqlSugar/Enum/ProperyType.cs index 245b91a18..3490c2b1a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Enum/ProperyType.cs +++ b/Src/Asp.NetCore2/SqlSugar/Enum/ProperyType.cs @@ -27,6 +27,13 @@ namespace SqlSugar @DateTimeOffset, @Single, @TimeSpan, - @char + @char, + @NpgsqlBox, + @NpgsqlCircle, + @NpgsqlLine, + @NpgsqlLseg, + @NpgsqlPath, + @NpgsqlPoint, + @NpgsqlPolygon, } } diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbBind/PostgreSQLDbBind.cs b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbBind/PostgreSQLDbBind.cs index 24997f630..c3508d44c 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbBind/PostgreSQLDbBind.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/DbBind/PostgreSQLDbBind.cs @@ -126,13 +126,9 @@ namespace SqlSugar new KeyValuePair("double precision",CSharpDataType.@int), new KeyValuePair("numeric",CSharpDataType.@decimal), new KeyValuePair("decimal",CSharpDataType.@decimal), - new KeyValuePair("path",CSharpDataType.@decimal), - new KeyValuePair("point",CSharpDataType.@decimal), - new KeyValuePair("polygon",CSharpDataType.@decimal), new KeyValuePair("boolean",CSharpDataType.@bool), new KeyValuePair("bool",CSharpDataType.@bool), - new KeyValuePair("box",CSharpDataType.@bool), new KeyValuePair("bytea",CSharpDataType.byteArray), new KeyValuePair("varchar",CSharpDataType.@string), @@ -146,7 +142,6 @@ namespace SqlSugar new KeyValuePair("char",CSharpDataType.@string), new KeyValuePair("character",CSharpDataType.@string), new KeyValuePair("cidr",CSharpDataType.@string), - new KeyValuePair("circle",CSharpDataType.@string), new KeyValuePair("tsquery",CSharpDataType.@string), new KeyValuePair("tsvector",CSharpDataType.@string), new KeyValuePair("txid_snapshot",CSharpDataType.@string), @@ -155,7 +150,6 @@ namespace SqlSugar new KeyValuePair("json",CSharpDataType.@string), new KeyValuePair("interval",CSharpDataType.@decimal), - new KeyValuePair("lseg",CSharpDataType.@decimal), new KeyValuePair("macaddr",CSharpDataType.@decimal), new KeyValuePair("money",CSharpDataType.@decimal), new KeyValuePair("timestamp",CSharpDataType.DateTime), @@ -184,6 +178,15 @@ namespace SqlSugar new KeyValuePair("number",CSharpDataType.@long), new KeyValuePair("number",CSharpDataType.@bool), new KeyValuePair("number",CSharpDataType.@decimal), + + + new KeyValuePair("box",CSharpDataType.@NpgsqlBox), + new KeyValuePair("circle",CSharpDataType.@NpgsqlCircle), + new KeyValuePair("lseg",CSharpDataType.@NpgsqlLseg), + new KeyValuePair("line",CSharpDataType.@NpgsqlLine), + new KeyValuePair("path",CSharpDataType.@NpgsqlPath), + new KeyValuePair("point",CSharpDataType.@NpgsqlPoint), + new KeyValuePair("polygon",CSharpDataType.@NpgsqlPolygon), }; public override List StringThrow { diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs index d97b0420f..a27f6dcfc 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs @@ -147,6 +147,20 @@ namespace SqlSugar { sqlParameter.NpgsqlDbType =((NpgsqlDbType)parameter.CustomDbType); } + else + { + switch (parameter.Value) + { + case NpgsqlBox b: sqlParameter.NpgsqlDbType = NpgsqlDbType.Box; break; + case NpgsqlCircle c: sqlParameter.NpgsqlDbType = NpgsqlDbType.Circle; break; + case NpgsqlLine l: sqlParameter.NpgsqlDbType = NpgsqlDbType.Line; break; + case NpgsqlLSeg s: sqlParameter.NpgsqlDbType = NpgsqlDbType.LSeg; break; + case NpgsqlPath p: sqlParameter.NpgsqlDbType = NpgsqlDbType.Path; break; + case NpgsqlPoint p: sqlParameter.NpgsqlDbType = NpgsqlDbType.Point; break; + case NpgsqlPolygon p: sqlParameter.NpgsqlDbType = NpgsqlDbType.Polygon; break; + default: break; + } + } } return result; }