[英]The type '' cannot be used as type parameter 'TEntityDto' in the generic type 'ICrudAppService'
我正在閱讀關於 abp.io 的教程:
https://docs.abp.io/en/abp/latest/Tutorials/Part-1?UI=MVC#create-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
”不能用作泛型類型或方法“ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>
”中的類型參數“TEntityDto
”。 沒有從“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; }
}
CreateUpdateBookDto 必須是相同的主鍵類型。
public class CreateUpdateBookDto: AuditedEntityDto<Guid> {
}
您正在混合:
Abp.Application.Services.ICrudAppService<TEntityDto, TPrimaryKey, ...>
Volo.Abp.Application.Dtos.IEntityDto<TKey>
對於 ABP 框架 (abp.io),使用Volo.Abp
package:
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" />
我遇到了同樣的問題並通過更改 DTO inheritance 修復了它
來自MyDto: AuditedAggregateRoot<Guid>
到MyDto: AuditedEntityDto<Guid>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.