首页 > 解决方案 > Microsoft.SqlServer.Types 与 .NET 标准不兼容

问题描述

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

我在转换我们的数据访问层代码时遇到了麻烦,因为我们广泛利用了 Microsoft.SqlServer.Types,而官方的 NuGet 包不支持 .NET Standard。我尝试了dotmorten 的非官方 NuGet 包,但它缺少很多功能。下面是我们需要的所有缺失的列表(放在一起以获得代码构建......)

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();
}

当我搜索其他试图将 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。那么你们所有人是如何做到这一点的呢?

标签: c#sql-server.net-standardsqlgeographysqlgeometry

解决方案


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

我们最终转向了 EF Core。


推荐阅读