无法将表达式转换为SQL,也无法将其视为本地表达式

时间:2018-07-25 20:27:20

标签: c# sql .net

我正在WCF中创建一个带给我SP的函数,并通过两个整数将其传递给参数,但是当我尝试保存或执行它时,会向我发送此错误消息:

  

无法将表达式'value(DataAccessName).spInsPerfilArea(1,4)'转换为SQL,也无法将其视为本地表达式。

有什么主意吗?

存储过程:

ALTER PROCEDURE [DB].[spInsPerfilArea]
    @PerfilId Int,
    @AreaId Int
    --@FechaCreacion DateTime,
    --@FechaUltimaModificacion DateTime = null

AS
BEGIN
SET NOCOUNT ON
IF EXISTS(SELECT 1 FROM  DB.TableName WHERE PerfilId =@PerfilId AND AreaId = @AreaId)
BEGIN
RETURN 0;
END

ELSE

BEGIN 

INSERT INTO DB.TableName (PerfilId, AreaId, FechaCreacion,FechaUltimaModificacion) 
            VALUES(@PerfilId,@AreaId,GETDATE(),GETDATE())

END

SET NOCOUNT OFF

END

功能

public static GuardarPerfilAreaRes GuardarPerfilArea(GuardarPerfilAreaReq req)
{
    var res = new GuardarPerfilAreaRes();
    try
    {
        using (var contexto = DataAccessDefaultDataContext.GetDataContext(Instancia.Mex))
            foreach (var idSelPerfil in req.PerfilArea.PerfilId)
            {
                var perfilArea = contexto.spInsPerfilArea(idSelPerfil, req.PerfilArea.AreaId);
                //perfilArea
            }

    }
    catch (Exception ex)
    {
        res.EstatusOperacion = new EstatusOperacion()
        {
            Exitoso = false,
            Mensaje = ex.Message
        };
    }
    return res;

}

班级:

  public class PerfilArea
    {

        [DataMember(Name = "PerfilId", IsRequired = true, Order =0)] 
        public int[] PerfilId { get; set; }

        [DataMember(Name = "AreaId", IsRequired = true, Order = 1)] 
        public int AreaId { get; set; }

      }

0 个答案:

没有答案