SQL地理空间类型Geography在SqlSugar如何查询,实体如何映射 返回
SQL地理空间类型Geography在SqlSugar如何查询,实体如何映射
热忱回答(11)
-
fate stay night VIP0
2019/5/18试试object类型
0 回复 -
1+1=1 VIP0
2019/5/18改成object类型查询报错,如下:
SqlSugar.SqlSugarException: SqlSugarException.NotSupportedException: "productdb.sys.geography" Type NotSupported, DbBindProvider.GetPropertyTypeName error.
用Microsoft.SqlServer.Types.SqlGeography类型,能查询,但取不到值
0 回复 -
fate stay night VIP0
2019/5/19static SqlSugarClient singleDb = new SqlSugarClient(
new ConnectionConfig()
{
ConfigId = 1,
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
ConfigureExternalServices=new ConfigureExternalServices() {
AppendDataReaderTypeMappings=new List<KeyValuePair<string, CSharpDataType>>() {
new KeyValuePair<string, CSharpDataType>("Geography",CSharpDataType.@object)
}
},
0 回复 -
fate stay night VIP0
2019/5/19这样可以解决
0 回复 -
1+1=1 VIP0
2019/5/20实体
namespace Test.Model
{
public class Country
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int ID { get; set; }
public string Name_CN { get; set; }
public Microsoft.SqlServer.Types.SqlGeography Location { get; set; }
}
}
SqlSugar:
using SqlSugar;
using System.Collections.Generic;
using System.Configuration;
namespace Test.Model
{
public class DbContext
{
public DbContext()
{
Database = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
ConfigureExternalServices = new ConfigureExternalServices()
{
AppendDataReaderTypeMappings = new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("Geography",CSharpDataType.@object)
}
}
});
}
public SqlSugarClient Database;
public SimpleClient<Country> Country { get { return new SimpleClient<Country>(Database); } }
}
}
取值
public class Test : DbContext
{
public void Demo()
{
var m = Country.GetById(1);
Console.WriteLine(m.Name_CN);
Console.WriteLine(m.Location.Long);
}
}
还是取不到值,异常信息
未经处理的异常: System.NullReferenceException: 未将对象引用设置到对象的实例。
请教这个要如何处理,烦请指导一下,谢谢
0 回复 -
1+1=1 VIP0
2019/5/24@fate stay night:有空帮看一下我的问题,谢谢
0 回复 -
fate stay night VIP0
2019/5/24这个功能会在下个版本修复 请关注 5.0.0.3版本,不需要你添加任何东西就能支持
0 回复 -
1+1=1 VIP0
2019/5/24@fate stay night:太棒了
0 回复 -
fate stay night VIP0
2020/12/10@1+1=1:
var xx = db.Queryable<zc_land>().Select(it => new zc_land(){
name=
it.name,
geom= Convert.ToString(it.geom)
}).ToList();0 回复 -
fate stay night VIP0
2020/12/10或者用自定义函数实现 st_astext
SELECT st_astext(geom), * FROM zc_land 或者 SELECT st_asewkt(geom), * FROM zc_land
默认tostring好像是 需求转码的
0 回复 -
fate stay night VIP0
2020/12/10看文档吧 我文档更新了:http://www.donet5.com/Home/Doc?typeId=1221
0 回复