在通用类型'ICrudAppService'中,类型''不能作为类型参数'TEntityDto'使用。

问题描述 投票:0回答:2

我在abp.io上看了一个教程。https:/docs.abp.ioenabplatestTutorialsPart-1?UI=MVC#cate-the-application-service。

和我创建的服务。

using Abp.Application.Services;

public interface IBookAppService : 
    ICrudAppService< //Defines CRUD methods
        BookDTO , //Used to show books
        Guid, //Primary key of the book entity
        PagedAndSortedResultRequestDto, //Used for paging/sorting on getting a list of books
        CreateUpdateBookDto, //Used to create a new book
        CreateUpdateBookDto> //Used to update a book
{

}

但界面显示错误

'类型'...BookDTO'不能作为类型参数'TEntityDto在通用类型或方法''中的''。ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>'. 从''到''没有隐式引用转换。BookDTO'至'。Abp.Application.Services.Dto.IEntityDto<System.Guid>'.

BookDTO 是这样的。

using Volo.Abp.Application.Dtos;

public class BookDTO : AuditedEntityDto<Guid>
{
    public string Name { get; set; }

    public BookType Type { get; set; }
    public DateTime PublishDate { get; set; }
    public float Price { get; set; }
}
c# asp.net-core generics abp
2个回答
0
投票

你在混。

  • Abp.Application.Services.ICrudAppService<TEntityDto, TPrimaryKey, ...>
  • Volo.Abp.Application.Dtos.IEntityDto<TKey>

对于ABP框架(abp.io),使用的是 Volo.Abp 包。

  • Volo.Abp.Application.Services.ICrudAppService<TEntityDto, in TKey, ...>

相关的。哪个才是真正的ASP.NET Boilerplate项目?

需要更改的文件

IBookAppService.cs。

// using Abp.Application.Services;
// using Abp.Application.Services.Dto;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

BookAppService.cs。

// using Abp.Application.Services;
// using Abp.Application.Services.Dto;
// using Abp.Domain.Repositories;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

CreateUpdateBookDTO.cs。

// using Abp.AutoMapper;

Acme.BookStore.Application.Contracts.csproj。

<!-- <PackageReference Include="Abp" Version="5.6.0" /> -->
<!-- <PackageReference Include="Abp.AutoMapper" Version="5.6.0" /> -->
<PackageReference Include="Volo.Abp" Version="2.6.2" />
<PackageReference Include="Volo.Abp.AutoMapper" Version="2.6.2" />

0
投票

CreateUpdateBookDto必须是相同的主键类型。

public class CreateUpdateBookDto: AuditedEntityDto<Guid> {
}
© www.soinside.com 2019 - 2024. All rights reserved.