EntityFramework: There is no mapping of the ObjectParameter object type to a native type managed provider

0

I'm developing an MVC application with Entity Framework in Code First.

As my database has procedures, I chose to use SQLQuery to execute the procedures, but I'm getting away with this error:

 Não existe mapeamento do tipo de objeto System.Data.Entity.Core.Objects.ObjectParameter para um provedor gerenciado de tipo nativo.

Here is the code for the DbContext class:

public DTODados GetDadosProcedure(string codUsuario, string senhaCript)
{
    return Database.SqlQuery<DTODados>("ProcedureGenerica", 
        codUsuario != null ?
            new ObjectParameter("codUsuario", codUsuario) :
            new ObjectParameter("codUsuario", typeof(string)), 
        senhaCript != null ?
            new ObjectParameter("senhaCript", senhaCript) :
            new ObjectParameter("senhaCript", typeof(string))
    ).SingleOrDefault();
}

Following this link

asked by anonymous 21.09.2017 / 19:46

1 answer

0

Resolved: I changed to SqlParameters and set the parameters correctly:

public DTODados GetDadosProcedure(string codUsuario, string senhaCript)
{
    return Database.SqlQuery<DTODados>("ProcedureGenerica @codUsuario , @senhaCript", 
        new SqlParameter("@codUsuario", codUsuario),
        new SqlParameter("@senhaCript", senhaCript) 
    ).SingleOrDefault();
}
    
21.09.2017 / 20:39