Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Z.EntityFramework.Plus报错 #179

Open
Hexiang1128 opened this issue Jul 31, 2022 · 12 comments
Open

使用Z.EntityFramework.Plus报错 #179

Hexiang1128 opened this issue Jul 31, 2022 · 12 comments

Comments

@Hexiang1128
Copy link

报错提示:Unable to cast object of type 'ShardingCore.EFCores.ShardingQueryCompiler' to type 'Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler'.
使用的是Z.EntityFramework.Plus查询未来的功能所产生的报错:source.DeferredCount().FutureValue();
请问这个如何解决?

@xuejmnet
Copy link
Collaborator

@Hexiang1128 批处理三方的查看文档里面的批处理兼容,因为三方批处理不属于efcore api但是shardingcore做了兼容直接看文档就知道了

@xuejmnet
Copy link
Collaborator

xuejmnet commented Aug 1, 2022

@Hexiang1128 不好意思我一开始以为是批处理的增删改查,原来是将多个查询聚合成一批然后查询这个功能目前不支持不好意思,后续可以考虑支持 因为是三方的api所以我自己了解的不多抱歉啊需要后续做支持

@Hexiang1128
Copy link
Author

@xuejmnet 谢谢,希望能够尽快支持

@zh3305
Copy link

zh3305 commented Nov 11, 2022

同问: 在批量删除时错误,不用批量删除会全部查出来一个一个删除,非常慢

Unable to cast object of type 'ShardingCore.EFCores.ShardingQueryCompiler' to type 'Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler'.
System.InvalidCastException: Unable to cast object of type 'ShardingCore.EFCores.ShardingQueryCompiler' to type 'Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler'.
   at .[](IQueryable`1)
   at Z.EntityFramework.Extensions.BatchDelete.Execute[T](IQueryable`1 query)

@xuejmnet
Copy link
Collaborator

@zh3305 不需要查询出来上面已经给解决方案了批量处理兼容任何三方框架

@xuejmnet
Copy link
Collaborator

@zh3305
Copy link

zh3305 commented Nov 11, 2022

@xuejmnet 我用的 就是 Z.EntityFramework.Plus 插件的 Repository.GetAll() .DeleteAsync(); 功能.
我知道 这个是Z.EntityFramework.Plus 插件的bug,他应该转换为 IQueryCompiler 而不是 QueryCompiler
只是反馈一下,

@xuejmnet
Copy link
Collaborator

@zh3305 这个不是zzz的bug是因为shardingcore替换了IQuerycompiler导致的不过我已经写了兼容的代码可以查看文档,刚刚我又把demo写了一下你可以看看
https://github.com/dotnetcore/sharding-core/blob/main/benchmarks/ShardingCoreBenchmark/ZZZDemo.cs

@zh3305
Copy link

zh3305 commented Nov 11, 2022

@xuejmnet 感谢大佬 搞定了

      public static async Task<int> ShardingBulkDeleteAsync<T>(this MonitorDbContext shardingDbContext, Expression<Func<T, bool>> where,
            CancellationToken cancellationToken = default(CancellationToken)) where T : class
        {
            var dbContexts = shardingDbContext.BulkShardingTableExpression(where);
            var effectRows = 0;
            foreach (var dbContext in dbContexts)
            {
                effectRows += await dbContext.Set<T>().Where(where)
                    .DeleteAsync( cancellationToken: cancellationToken);
            }

            return effectRows;
        }

@xuejmnet
Copy link
Collaborator

@zh3305 嗯好的 :)

@xuejmnet
Copy link
Collaborator

xuejmnet commented Nov 11, 2022

@zh3305 后续我尝试把ShardingCore的ShardingQueryComplier通过继承QueryComplier来实现分片目前是直接继承的接口,如果通过继承父类起码未分片的表不会报错,只有分片表会报错报找不到表这样或许好一点

xuejmnet added a commit that referenced this issue Nov 11, 2022
…这样可以保证未分片的表使用zzz不需要处理修改还是支持的,仅分片表处理需要特殊考虑
@xuejmnet
Copy link
Collaborator

@zh3305 @Hexiang1128 最新版本6.8.0.7和7.0.0.2已经修复了针对普通对象的操作,仅分片对象需要特殊处理:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants