首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >内存优化表不支持保存点(EF core 5)

内存优化表不支持保存点(EF core 5)
EN

Stack Overflow用户
提问于 2020-11-30 18:34:09
回答 1查看 191关注 0票数 2

使用新功能SavePoints将EF核心版本3.1升级到5(使用交易手册时自动创建)

我在SQL Server 2016中有一个名为"Content“的内存优化表。

当我调用"SaveChanges“命令时,系统抛出异常”内存优化表不支持创建保存点“。如何关闭保存点?

注意:如果我使用TransactionScope,则传递success。

请给我处理这种情况的解决方案https://docs.microsoft.com/en-us/ef/core/saving/transactions

EN

回答 1

Stack Overflow用户

发布于 2020-12-01 10:02:37

我想在没有外键的两个表中插入行。

startup.cs文件中的

代码语言:javascript
复制
public void ConfigureServices(IServiceCollection services)
    {
        services.AddHealthChecks();
        services.AddDbContext<wUtilityContentContext>(opts => opts.UseSqlServer(
           Algorithm.Decrypt(Configuration["ConnectionStrings:wUtilityContent_ConnectionString"]),
           b => b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)));

        services.AddUnitOfWorkPool(optionsBuilder =>
        {
            optionsBuilder.AddUnitOfWork<wUtilityContentContext>("Content");
        });
        services.AddScoped<IContentUow, ContentUow>();
        services.AddScoped<AuditCoreLog>();
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        ....
    }

ContentService.cs文件中的

代码语言:javascript
复制
public class ContentServices : ContentServiceBase
{
    private readonly AuditCoreLog _auditLog;
    private readonly IContentUow _contentUow;
    public ContentServices(IContentUow contentUow, AuditCoreLog auditLog)
    {
        _contentUow = contentUow;
        _auditLog = auditLog;
    }
    public override Task<MessageResponse> CategoryInsertUpdate(CategoryInsertUpdate_Request request, ServerCallContext context)
    {
        var response = new MessageResponse() { };
        try
        {
            int _RESPONSE_EXISTED_CATE = -2;
            int _RESPONSE_NOT_EXISTS_CATE = -3;
            int _nHotOrder = 0;
            var findnHotOrder = _contentUow.Category.Where(p => p.ParentId == request.ParentId).ToList();
            if (findnHotOrder != null && findnHotOrder.Count > 0)
               _nHotOrder = findnHotOrder.Max(x => x.OrderNo).GetValueOrDefault();
            var insertCategory = _contentUow.Category.Add(new TblCategory()
            {
                    ParentId = request.ParentId,
                    Alias = request.Alias,
                    OrderNo = _nHotOrder + 1,
                    Status = request.Status,
                    CreatedDate = DateTime.Now,
                    CreatedUser = request.CreatedUser,
                    SystemId = request.SystemId,
                    ImageUrl = request.ImageUrl
            });

                _contentUow.SaveChanges(); //savechange to DB -> get id identity
                var _categoryId = insertCategory.Entity.Id;
                var insertCategoryContent_vi = _contentUow.CategoryContent.Add(new TblCategoryContent()
                {
                    CategoryId = _categoryId,
                    CategoryName = request.CategoryNameVi,
                    CategoryContent = request.CategoryContentVi,
                    LanguageId = (int)PaymentApps_PaymentLanguage.VN
                });

                var insertCategoryContent_en = _contentUow.CategoryContent.Add(new TblCategoryContent()
                {
                    CategoryId = _categoryId,
                    CategoryName = request.CategoryNameEn,
                    CategoryContent = request.CategoryContentEn,
                    LanguageId = (int)PaymentApps_PaymentLanguage.EN
                });
            _contentUow.SaveChanges();
            _contentUow.CommitTransaction();
            response.ResponseStatus = ErrorCodes.SUCCESS;
        }
        catch (Exception ex)
        {
            response.ResponseStatus = ErrorCodes.SYSTEM_ERROR;
            _contentUow.RollbackTransaction();
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65071903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档