Starts in:
1 DAY
5 HRS
22 MIN
33 SEC
Starts in:
1 D
5 H
22 M
33 S
Open Closed

abp suite 多对多关系生成的代码,更新时报内部错误 #6477


User avatar
0
829098@qq.com created
  • ABP Framework version: v8.0
  • UI Type: Angular / MVC / Blazor WASM / Blazor Server
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..) / MongoDB
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

复现步骤 1、生成代码 ProjectTask,添加多对多的导航属性IdentityUser 2、运行系统,添加一行ProjectTask,添加两个IdentityUser,保存,正常 3、编辑ProjectTask,删除其中一个IdentityUser,保存,报内部服务器错误 4、编辑ProjectTask,删除其中一个IdentityUser,添加新的IdentityUser,保存,同样报错


20 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ABP CLI 和 SUITE的版本是? 错误日志是?

  • User Avatar
    0
    829098@qq.com created

    ABP CLI 和 SUITE的版本是? 错误日志是?

    ABP CLI 是 最新的版本 abp suite update --p 没有看到错误日志,代码到这里就报错了(通用内部方法,调试不了) return await _projectTaskRepository.UpdateAsync(projectTask);

  • User Avatar
    0
    829098@qq.com created

    您直接生成代码试试就知道了,只要是导航的多对多关系,只要做了删除操作,保存时就一定会报错的。

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你先分享一下内部服务器错误的日志.

  • User Avatar
    0
    829098@qq.com created

    你先分享一下内部服务器错误的日志.

    去哪里查看错误日志

  • User Avatar
    0
    829098@qq.com created

    你先分享一下内部服务器错误的日志.

    你用abp suite 可以复现的。没有改动任何代码。

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    App logs:

    YourWebHostProject/Logs/logs.txt

    Suite logs: C:\Users\usernmae.abp\suite\logs

  • User Avatar
    0
    829098@qq.com created

    App logs:

    YourWebHostProject/Logs/logs.txt

    Suite logs: C:\Users\usernmae.abp\suite\logs

    查看了,操作后,发现日志没有记录任何报错信息

  • User Avatar
    0
    829098@qq.com created

    请你花几分钟, 1、使用abp suite 创建A对象,关联B对象(多对多导航关系), 2、运行代码 3、创建A对象时,关联选择一个或者多个B对象, 4、编辑A对象,把其中的B对象删除一个,点击保存,报错。

  • User Avatar
    0
    829098@qq.com created

    生成的代码,选择 ApplicationTemplate,MVC,MS SQL SERVER 数据库

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    好的

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    这是我的到的错误日志

    [11:12:11 ERR] ---------- RemoteServiceErrorInfo ----------
    {
      "code": null,
      "message": "An internal error occurred during your request!",
      "details": null,
      "data": {},
      "validationErrors": null
    }
    
    [11:12:11 ERR] The property 'BookAuthor.BookId' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal.
    System.InvalidOperationException: The property 'BookAuthor.BookId' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal.
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
     
    
  • User Avatar
    0
    829098@qq.com created

    这是我的到的错误日志

    [11:12:11 ERR] ---------- RemoteServiceErrorInfo ---------- 
    { 
      "code": null, 
      "message": "An internal error occurred during your request!", 
      "details": null, 
      "data": {}, 
      "validationErrors": null 
    } 
     
    [11:12:11 ERR] The property 'BookAuthor.BookId' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal. 
    System.InvalidOperationException: The property 'BookAuthor.BookId' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal. 
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey) 
      
    

    错误日志在哪里能看到,我从YourProjectWebHost目录的 logs文件夹打开的log文件,是没有这个信息的。另外,这个错误有什么处理建议吗

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    我会尝试解决这个错误,请稍等.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    这是EF Core 8 的一个bug

    请关注 https://github.com/dotnet/efcore/issues/32383

    我会尝试找一个解决方案

  • User Avatar
    0
    829098@qq.com created

    这是EF Core 8 的一个bug

    请关注 https://github.com/dotnet/efcore/issues/32383

    我会尝试找一个解决方案

    好的,感谢大神,期待早日解决。

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你好

    你改成DeleteBehavior.Cascade, 之后添加新迁移, 数据库就可以了

  • User Avatar
    0
    829098@qq.com created

    你好

    你改成DeleteBehavior.Cascade, 之后添加新迁移, 数据库就可以了

    谢谢,是不是abp suite 生成代码时,不要勾选 数据库迁移,在生成代码之后,在解决方案里边,找到生成的代码,改为 DeleteBehavior.Cascad,然后设置 迁移项目为启动项目,执行迁移的方式即可?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    这样也是可以的.

  • User Avatar
    0
    829098@qq.com created

    多谢,问题已解决。

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06