【问题标题】:How to call and get result of scalar valued function using entity framework如何使用实体框架调用并获取标量值函数的结果
【发布时间】:2016-04-25 14:51:44
【问题描述】:

我正在使用 Entity Framework 6.0

我在 SQL Server 中有标量值函数,签名为

fn_CartAmount(@CartId bigint) RETURNS decimal(18,2)


我想从 Entity Framework 调用这个函数并得到它的结果。

【问题讨论】:

    标签: c# .net sql-server entity-framework


    【解决方案1】:

    你可以试试这样的:

        public decimal GetCartAmount(int cartId)
        {
    
            var returnCode = new SqlParameter("@ReturnCode", SqlDbType.Bit) { Direction = ParameterDirection.Output };
    
            object[] parameters =
            {
                new SqlParameter(@"CartId", SqlDbType.BigInt) {Value = cartId}
                , returnCode
            };
    
            string command = string.Format("exec @ReturnCode = dbo.fn_CartAmount @CartId");
            Database.ExecuteSqlCommand(command, parameters);
    
    
            return (decimal)returnCode.Value;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      相关资源
      最近更新 更多