调用DeleteAsync时获取歧义匹配发现异常 [英] Getting Ambiguous match found exception while calling 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);
StackTrace:
StackTrace:
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:\Github\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.cs:line 310
at Abp.Domain.Repositories.AbpRepositoryBase`2.FirstOrDefault(TPrimaryKey id) in D:\Github\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.cs:line 108
at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.Delete(TPrimaryKey id) in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Repositories\EfCoreRepositoryBaseOfTEntityAndTPrimaryKey.cs:line 216
at Abp.Domain.Repositories.AbpRepositoryBase`2.DeleteAsync(TPrimaryKey id) in D:\Github\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.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:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.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:\Users\viveknuna\source\repos\Stanchion\aspnet-core\src\Nec.Stanchion.Business.Services\Suppliers\SupplierAppService.cs:line 53
推荐答案
Ambiguous match found
可能是由于Id
的属性隐藏在实体框架中引起的. FullAuditedEntity<int>
已经与您所做的相同地定义了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屋!