Raw Entity Framework

0

I'm trying to call a SQL Server query from Raw

var result = context.Database.SqlQuery<UniversalExtend>("SELECT distinct(PC.ProductoCatalogoId)," +
                                                                    " P.Nombre + ' ' + PL.Product + ' ' + E.Nombre + ' ' + O.NombreOpcion AS Descripcion, PC.PrecioVenta" +
                                                                    " FROM ProductoCatalogos AS PC" +
                                                                    " INNER JOIN Productos AS P ON PC.ProductoId = P.ProductoId" +
                                                                    " INNER JOIN EspecificacionCatalogos AS EC ON PC.ProductoCatalogoId = EC.ProductoCatalogoId" +
                                                                    " INNER JOIN EspecificacionProductos AS EP ON EC.EspecificacionProductoId = EP.EspecificacionProductoId" +
                                                                    " INNER JOIN Especificaciones AS E ON EP.EspecificacionId = E.EspecificacionId" +
                                                                    " AND E.EspecificacionId = @colorId",
                new SqlParameter("@colorId", colorId) +
                " INNER JOIN Opciones AS O ON EC.OpcionId = O.OpcionId" +
                " CROSS APPLY(" +
                " SELECT E.Nombre + ' ' + O.NombreOpcion AS 'Product'" +
                " FROM ProductoCatalogos AS PC" +
                " INNER JOIN Productos AS P ON PC.ProductoId = P.ProductoId" +
                " INNER JOIN EspecificacionCatalogos AS EC ON PC.ProductoCatalogoId = EC.ProductoCatalogoId" +
                " INNER JOIN EspecificacionProductos AS EP ON EC.EspecificacionProductoId = EP.EspecificacionProductoId" +
                " INNER JOIN Especificaciones AS E ON EP.EspecificacionId = E.EspecificacionId" +
                " AND E.EspecificacionId = @tallaId", new SqlParameter("@tallaId", tallaId) +
                                                      " INNER JOIN Opciones AS O ON EC.OpcionId = O.OpcionId" +
                                                      " ) PL" +
                                                      " WHERE P.Nombre LIKE '%' + @valor + '%'",
                new SqlParameter("@valor", valor)).ToList();

The error is as follows:

  

When executing a command, parameters must be exclusively database parameters or values.

    
asked by Pedro Ávila 09.10.2018 в 08:06
source

1 answer

0

You can solve my problem thanks to the recommendation of @Pikoh

var result = context.Database.SqlQuery<UniversalExtend>("SELECT distinct(PC.ProductoCatalogoId)," +
                                                                    " P.Nombre + ' ' + PL.Product + ' ' + E.Nombre + ' ' + O.NombreOpcion AS Descripcion, PC.PrecioVenta" +
                                                                    " FROM ProductoCatalogos AS PC" +
                                                                    " INNER JOIN Productos AS P ON PC.ProductoId = P.ProductoId" +
                                                                    " INNER JOIN EspecificacionCatalogos AS EC ON PC.ProductoCatalogoId = EC.ProductoCatalogoId" +
                                                                    " INNER JOIN EspecificacionProductos AS EP ON EC.EspecificacionProductoId = EP.EspecificacionProductoId" +
                                                                    " INNER JOIN Especificaciones AS E ON EP.EspecificacionId = E.EspecificacionId" +
                                                                    " AND E.EspecificacionId = @colorId" +
                                                                    " INNER JOIN Opciones AS O ON EC.OpcionId = O.OpcionId" +
                                                                    " CROSS APPLY(" +
                                                                    " SELECT E.Nombre + ' ' + O.NombreOpcion AS 'Product'" +
                                                                    " FROM ProductoCatalogos AS PC" +
                                                                    " INNER JOIN Productos AS P ON PC.ProductoId = P.ProductoId" +
                                                                    " INNER JOIN EspecificacionCatalogos AS EC ON PC.ProductoCatalogoId = EC.ProductoCatalogoId" +
                                                                    " INNER JOIN EspecificacionProductos AS EP ON EC.EspecificacionProductoId = EP.EspecificacionProductoId" +
                                                                    " INNER JOIN Especificaciones AS E ON EP.EspecificacionId = E.EspecificacionId" +
                                                                    " AND E.EspecificacionId = @tallaId" +
                                                                    " INNER JOIN Opciones AS O ON EC.OpcionId = O.OpcionId" +
                                                                    " ) PL" +
                                                                    " WHERE P.Nombre LIKE '%' + @valor + '%'",
                new SqlParameter("@colorId", colorId), new SqlParameter("@tallaId", tallaId),
                new SqlParameter("@valor", valor)).ToList();

Greetings!

    
answered by 09.10.2018 / 16:49
source