- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近将我的一个 ASP.NET Core 应用程序从 net461 应用程序升级到 ASP.NET Core 2.0 应用程序,因为过去唯一阻碍我的是 System.Transactions(现在受支持)。
升级后,访问任何使用以下函数的函数时出现错误:
protected static TransactionScope GetTransactionScope()
{
TransactionOptions transactionOptions = new TransactionOptions
{
IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
Timeout = TransactionManager.MaximumTimeout
};
return new TransactionScope(TransactionScopeOption.Required, transactionOptions);
}
错误:
Enlisting in Ambient transactions is not supported.
根据我的谷歌研究,我在 GitHub 上看到了一些与此相关的未解决问题,他们都说将 System.Data.SqlClient 升级到最新的预发布版本将解决这个问题。
我相信这解决了那个问题,但引起了另一个问题。我在我的项目中使用 Dapper v1.50.2,我认为它无法使用 System.Data.SqlClient 的预发布版本,因为我现在收到以下错误:
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception
有谁知道我如何使用 Dapper 并摆脱这个环境事务错误?我不确定发生此类错误时如何移植 System.Transactions。
最佳答案
我最近解决了这个问题。首先,在您的 Web.csproj 中替换
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
与
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.AzureAppServicesIntegration" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.Internal" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Extensions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Localization" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Localization.Routing" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.MiddlewareAnalysis" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.NodeServices" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.HttpSys" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Razor" Version="2.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.TraceSource" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.WebEncoders" Version="2.0.0" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.1" />
在这个包引用中,我删除了所有关于 EntityFramework 和 SqlServer 缓存的引用。然后,添加对旧 System.Data.SqlClient 的引用
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
希望对您有所帮助!
关于c# - 将 System.Data.SqlClient 升级到版本 4.5.0-preview2 后,Dapper 抛出 System.Data.SqlClient.SqlConnection 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47421371/
有谁知道或有如何使用的链接https://github.com/henkmollema/Dapper-FluentMap在我的 Dapper CRUD 中?现在我正在使用 Dapper.Contrib
我正在寻找一种方法来仅更新 Dapper 中的设置属性。即仅当实体的属性不为空时才更新实体的属性。 我正在用一种相当粗糙的方法解决同样的问题,如下所示,但我相信应该有一种更简洁的方法来做到这一点。
方案: 我的模型中有一个字符串属性,其中包含MultiSelectList @Html.ListBox的ID。如果选择两个列表项,则我的属性值将类似于0100,0500。 问题: Dapper whe
我们正在使用 Dapper 进行一些数据访问事件,并使用标准推荐方法连接到数据库,如下所示: public static Func ConnectionFactory = () => new SqlC
是否可以通过表名 作为 Dapper Query 命令的参数?我不是在寻找 SQL 表定义的函数或 SQL 表变量。我想在 C# 中定义表名并将其传递给 Dapper。这是我的代码,执行时返回错误 M
我在dapper中尝试对包含NULL的列进行拆分时遇到MultiMaps问题。 Dapper似乎不实例化对象,并且我的映射函数接收null而不是对象。 这是我的新测试: class Produ
我似乎找不到我的问题的文档或示例(现在已经搜索了一段时间)。我认为我的问题很简单,所以这里是。 我有两张 table 。我的主表称为 Persons,辅助表是 PersonEntries。对于 Per
我的代码有点问题,我想让 dapper 很好地使用它。 当我说我的代码是继承的,所以这不是我的设计。 我正在尝试替换 Entity Framework,因为对数据库的调用效率不高,所以我想更好地控制生
我已经开始玩 Dapper.Net,到目前为止我真的很喜欢它 - 然而,我遇到了一个问题。 假设我有一个 POCO 类: public class Person { public string
我已经开始玩 Dapper.Net,到目前为止我真的很喜欢它 - 然而,我遇到了一个问题。 假设我有一个 POCO 类: public class Person { public string
我知道这是一种错误的做法,但我正在处理具有 NULLS 的遗留代码库,当它表示空字符串时,反之亦然。 我无法立即看到它是如何可能的,但是当从数据库映射回来时,是否有可能获取(或修改 dapper 以便
我正在尝试选择一个包含 2 个整数列的列表,将结果映射到一个元组。举个例子: return connection.Query>("select id1, id2 from sometable").To
我有一个存储过程,它有一个没有默认值的参数,但它可以为空。但我不知道如何使用 Dapper 传递 null。我可以在 ADO 中做得很好。 connection.Execute("spLMS_Upda
我决定使用 Dapper.net,因为它似乎只做我想做的事情:映射,我不需要任何花哨的东西,我只是厌倦了处理我的数据读取器和我的对象之间的映射。 我的问题: 假设我有这些类(class): class
我在从 Dapper 查询返回单个对象时遇到问题。我有一个简单的查询,我想从返回的集合中获取第一个对象。我错过了什么? using (SqlConnection sqlConnection = new
假设我的实体是 public class AppUser { string Id { get; set; } string Name { get; set; } } 看起来默认情况下
我在Dapper官方文档中看到了QueryMultiple,如下所示,很方便! var sql = @" select * from Customers where CustomerId =
我正在使用 Dapper 查询包含 XML 字段的表: CREATE TABLE Workflow ( Guid uniqueidentifier not null, State xm
我有一个来自Dapper查询的动态结果,其中包含如下记录: {DapperRow, billing_currency_code = 'USD', count(*) = '6'} 我可以使用rowVar
我正在使用 Dapper 扩展,但我的数据库中有多个架构名称。 我在下面的链接中找到了答案,但它假设我只有一个模式名称,这不是我的情况。 Dapper Extensions Change Schema
我是一名优秀的程序员,十分优秀!