GithubHelp home page GithubHelp logo

Comments (4)

LambertW avatar LambertW commented on May 20, 2024

至于使用了Scoped方式后,EntityFrameworkCore.Triggers中报错问题,
请尝试使用

Triggers<SysMenu>.Updating += entry =>
            {
                var parentMenu = entry.Context.Set<SysMenu>().Find(entry.Entity.ParentId);
                entry.Entity.SortIndex = entry.Entity.Id;
                entry.Entity.MenuPath = (parentMenu?.MenuPath ?? "0") + "," + entry.Entity.Id;
            };

from zxw.framework.netcore.

VictorTzeng avatar VictorTzeng commented on May 20, 2024

谢谢指正。在项目里,DbContext和Repository的生命周期都由DI控制。DbContext的生命周期我是参照AddDbContext来的,源码里是用的AddSingleton。我刚刚测试了一下,改为Scoped后会报错,提示无法访问已释放过的资源。改为Singleton和Transient都没问题。

from zxw.framework.netcore.

LambertW avatar LambertW commented on May 20, 2024

谢谢指正。在项目里,DbContext和Repository的生命周期都由DI控制。DbContext的生命周期我是参照AddDbContext来的,源码里是用的AddSingleton。我刚刚测试了一下,改为Scoped后会报错,提示无法访问已释放过的资源。改为Singleton和Transient都没问题。

我已经测试过了,此问题是由Triggers引起,解决方式也在以上列出。

entry.Context.Set<SysMenu>().Find(entry.Entity.ParentId);

from zxw.framework.netcore.

VictorTzeng avatar VictorTzeng commented on May 20, 2024

我已经修改了和更新了nuget,并将demo分离出来新建了一个repository。万分感谢指正~~ @LambertW

from zxw.framework.netcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.