与.NET Standard不兼容的Microsoft.SqlServer.Types

时间:2019-01-30 19:28:24

标签: c# sql-server .net-standard sqlgeography sqlgeometry

由于我们开始利用.NET Core,因此我正在尝试将所有C#类库从.NET Framework转换为.NET Standard项目,因此需要同时由.NET Core和.NET Framework应用程序使用。 (后者将在未来几个月内移植到Core。)

我在转换数据访问层代码时遇到了麻烦,因为我们广泛利用了Microsoft.SqlServer.Types,而official nuget package不支持.NET Standard。我尝试了unofficial nuget package by dotmorten,但缺少许多功能。下面列出了我们需要缺少的所有东西(将它们扔在一起以构建代码...)

public static class SqlMockExtensions
    {
        public static SqlBytes STAsBinary(this SqlGeography geography) => throw new NotImplementedException();

        public static SqlGeography MakeValid(this SqlGeography geography) => throw new NotImplementedException();

        public static int STDimension(this SqlGeography geography) => throw new NotImplementedException();

        public static bool STIsValid(this SqlGeography geography) => throw new NotImplementedException();

        public static Nullable<double> EnvelopeAngle(this SqlGeography geography) => throw new NotImplementedException();

        public static SqlGeography ReorientObject(this SqlGeography geography) => throw new NotImplementedException();

        public static SqlGeography BufferWithTolerance(this SqlGeography geography, double arg1, int arg2, bool arg3) => throw new NotImplementedException();

        public static SqlGeography Reduce(this SqlGeography geography, double tolerance) => throw new NotImplementedException();

        public static SqlGeography EnvelopeCenter(this SqlGeography geography) => throw new NotImplementedException();

        public static double STDistance(this SqlGeography geography, SqlGeography point2) => throw new NotImplementedException();

        public static SqlBytes STAsBinary(this SqlGeometry geometry) => throw new NotImplementedException();
    }

当我search SO尝试将Microsoft.SqlServer.Types集成到其.NET Core和Standard项目中的其他人时,我看到有人提到要包括官方的nuget程序包,然后再执行以下操作:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

但是,当您尝试将不符合.NET Standard的nuget程序包添加到.NET Standard项目中时,它会出错,因此我不清楚这是一个解决方案。

这似乎是一个非常普遍的问题,必须有很多开发人员利用Microsoft.SqlServer.Types来实现SqlGeography,SqlGeometry等,并正在移植到.NET Standard。那么你们所有人是如何做到的?

1 个答案:

答案 0 :(得分:0)

对于它的价值,我们没有找到答案。

我们最终转向了 EF Core。