调用 DeleteAsync 时出现歧义匹配发现异常 [英] Getting Ambiguous match found exception while calling DeleteAsync

查看:27
本文介绍了调用 DeleteAsync 时出现歧义匹配发现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,它有代码作为主键而不是 Id,当我调用 DeleteAsync 方法时,我得到异常 Ambiguous match found.

I have a table which has code as primary key instead of Id, When I call DeleteAsync method I get the exception Ambiguous match found.

[Table("Test")]

public class Test: FullAuditedEntity<int>

{

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
new public int Id { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public virtual int Code { get; set; }

_testRepository.DeleteAsync(code);

堆栈跟踪:

   at System.RuntimeType.GetPropertyImpl(String name, BindingFlags 
bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetProperty(String name, BindingFlags bindingAttr)
   at System.Reflection.TypeExtensions.GetProperty(Type type, String name, BindingFlags bindingAttr)
   at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName)
   at Abp.Domain.Repositories.AbpRepositoryBase`2.CreateEqualityExpressionForId(TPrimaryKey id) in D:GithubaspnetboilerplatesrcAbpDomainRepositoriesAbpRepositoryBase.cs:line 310
   at Abp.Domain.Repositories.AbpRepositoryBase`2.FirstOrDefault(TPrimaryKey id) in D:GithubaspnetboilerplatesrcAbpDomainRepositoriesAbpRepositoryBase.cs:line 108
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.Delete(TPrimaryKey id) in D:GithubaspnetboilerplatesrcAbp.EntityFrameworkCoreEntityFrameworkCoreRepositoriesEfCoreRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 216
   at Abp.Domain.Repositories.AbpRepositoryBase`2.DeleteAsync(TPrimaryKey id) in D:GithubaspnetboilerplatesrcAbpDomainRepositoriesAbpRepositoryBase.cs:line 206
   at Castle.Proxies.Invocations.IRepository`2_DeleteAsync_58.InvokeMethodOnTarget()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:GithubaspnetboilerplatesrcAbpDomainUowUnitOfWorkInterceptor.cs:line 83
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.IRepository`2Proxy_16.DeleteAsync(Int32 id)
   at Nec.Stanchion.Business.Services.Suppliers.SupplierAppService.<DeleteSupplier>d__3.MoveNext() in C:Usersviveknunasource
eposStanchionaspnet-coresrcNec.Stanchion.Business.ServicesSuppliersSupplierAppService.cs:line 53

推荐答案

Ambiguous match found 可能是由于实体框架中 Id 的属性隐藏造成的.FullAuditedEntity 已经定义了与您所做的完全相同的 Id,因此您可以将其删除.

Ambiguous match found is likely caused by property hiding of Id in Entity Framework. FullAuditedEntity<int> already defined Id identically to what you do, so you can remove that.

另一方面,_testRepository.DeleteAsync(code) 通过比较 Id 来删除.要通过 code 删除,请执行 _testRepository.DeleteAsync(test => test.Code == code);

On another note, _testRepository.DeleteAsync(code) deletes by comparing the Id. To delete by code, do _testRepository.DeleteAsync(test => test.Code == code);

这篇关于调用 DeleteAsync 时出现歧义匹配发现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆