【问题标题】:The type '' cannot be used as type parameter 'TEntityDto' in the generic type 'ICrudAppService'类型“”不能用作泛型类型“ICrudAppService”中的类型参数“TEntityDto”
【发布时间】:2020-04-30 07:50:49
【问题描述】:

我正在浏览 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&lt;TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput&gt;”中的类型参数“TEntityDto”。没有从“BookDTO”到“Abp.Application.Services.Dto.IEntityDto&lt;System.Guid&gt;”的隐式引用转换。

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


【解决方案1】:

你在混音:

  • Abp.Application.Services.ICrudAppService&lt;TEntityDto, TPrimaryKey, ...&gt;
  • Volo.Abp.Application.Dtos.IEntityDto&lt;TKey&gt;

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

  • Volo.Abp.Application.Services.ICrudAppService&lt;TEntityDto, in TKey, ...&gt;

相关:Which is the real ASP.NET Boilerplate project?

要更改的文件

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" />

【讨论】:

    【解决方案2】:

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

    public class CreateUpdateBookDto: AuditedEntityDto<Guid> {
    }
    

    【讨论】:

    • 你是如何从这个问题中推断出来的?
    • 我曾在 abp 工作过,但他们的文档中缺少该部分。希望对你有用
    • 不,它没有用。请找到 repo 项目-github.com/udaysoni18/Abp-Project
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    相关资源
    最近更新 更多