Exception when querying using DTO in EF . core

Asked

Viewed 63 times

-1

I get the following error when executing the query:

"Cannot create a DbSet for 'Cliente_dto' because this type is not included in the model for the context."

public IQueryable<TEntity> CommandSql (string commandSql) 
{
    return dataBase.Set<TEntity>().FromSql(commandSql);                    
}
  • Cliente_dto is not a class configured for such an operation, so which class determines Cliente (I believe that’s the one)?

  • Yes, I have the customer class. But with the Customer class_dto needed to return data that is not present in the customer class.

  • There is not much logic to it, you need to create a minimal example for people to know well what only this code says nothing...

  • For example, join with another table and return data from tabs to tables.

  • dataBase.Set<TEntity>().FromSql(commandSql); when you do so with Set<> you are asking the code that type, as the type does not exist if you can not use it there ...

1 answer

-1


There is no way to return a Dbset from a dto class. You have to search for the information in the Entity classes and then you populate the dto class with this information.

What you can also do is use Link that you query and create the object.

Ex.:

   var dto = from cliente in clientes 
     join endereco in enderecos on cliente.id equals endereco.idCliente
     select new ClienteDto (){ Nome = cliente.nome , Rua = endereco.rua };

Browser other questions tagged

You are not signed in. Login or sign up in order to post.