0
I’m getting the following error:
Unable to convert from "Tclient" to "Easysistema.Models.Applicationclient"
public class ClientManager<TClient>
{
private ApplicationDbContext _context;
public ClientManager(ApplicationDbContext context)
{
_context = context;
}
public virtual async Task CreateClientAsync(TClient client)
{
var result = await _context.Clientes.Add(client);
if (result.Succeeded)
{
_context.SaveChanges();
}
return Task.FromResult(result);
}
}
The call is being made through:
var result = await _clientManager.CreateClientAsync(client);
That is the definition of _clientManager:
private readonly ClientManager<ApplicationClient> _clientManager;
public ClientController (
ClientManager<ApplicationClient> clientManager)
{
_userManager = userManager;
}
Applicationdbcontext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid, ApplicationUserClaim, ApplicationUserRole,
ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public virtual DbSet<ApplicationClient> Clientes { get; set; }
And this is my Applicationclient:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
namespace EasySistema.Models
{
public class ApplicationClient
{
[Key]
public Guid Id { get; set; }
[Required]
[Display(Name = "Tipo Pessoa")]
public int TipoPessoa { get; set; }
}
Could you please help me, because I can’t see where I’m going wrong, and I can’t fix it.
Your class
ClientManager
is waiting for a class of the typeTClient
and notApplicationClient
, therefore, in makingprivate readonly ClientManager<ApplicationClient> _clientManager;
is causing the error. Unless the classApplicationClient
heiress ofTClient
, it’s different there.– João Martins
I believe it will be otherwise it is receiving Tclient but expects to receive Easysistema.Models.Applicationclient is not ? so I did
private readonly ClientManager<ApplicationClient> _clientManager;
in order to pass "Easysistema.Models.Applicationclient".– Matheus
Or that you’re talking about Generics on
TClient
were simplyT
which does not seem to be for the rest of the context– Leandro Angelo
Your collection
ApplicationDbContext.Clientes
is a collection with the typeApplicationClient
?– Pagotti
Pagotti put my Applicationdbcontext in my question
– Matheus
What is the
TClient
and why you’re using her?– Leandro Angelo
My idea was through Tclient pass the parameter
EasySistema.Models.ApplicationClient
through the construction of theprivate readonly ClientManager<ApplicationClient> _clientManager;
but it’s not working out the way– Matheus