'ASP.NET Core 6 Create data in the database with swagger

As it says in the title, I want to save data in the database by entering the data in the swagger, for this I made a service layer and controller and in the backend is the model and in frontend the dto.

Service Class

 public async Task<SuperHeroDto> Create(SuperHeroDto dto)
    {
        #region
        _firstAPIDatabaseContext.SuperHeroes.Add(dto); 
        var saveChangesAsync= await  _firstAPIDatabaseContext.SaveChangesAsync();
        
    } 

I have the problem here: _firstAPIDatabaseContext.SuperHeroes.Add(dto);

enter image description here

I want to learn it on my own, but need tips on how to do it. I also created a profile for folders



Solution 1:[1]

I don't know the difference between SuperHeroDto and SuperHero in your code.

But obviously the code you provided is wrong to store SuperHeroDto objects in SuperHeroes.

Maybe you can write

_firstAPIDatabaseContext.SuperHeroeDto.Add(dto);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason