转:Entity FrameWork利用Database.SqlQuery执行存储过程并返回参数

   public IEnumerable<Statistic> GetStatistics(IEnumerable<Guid> itemIds)

        {

            var ctx = new DBContext();



            return ctx.Database.SqlQuery<Statistic>("[dbo].[ItemStatisticsSelect] @Items, @IsPostModeration",

                new SqlParameter("Items", string.Join("|", itemIds)),

                new SqlParameter("IsPostModeration", true));

        }
/// <summary>  

        /// 执行原始SQL命令  

        /// </summary>  

        /// <param name="commandText">SQL命令</param>  

        /// <param name="parameters">参数</param>  

        /// <returns>影响的记录数</returns>  

        public Object[] ExecuteSqlNonQuery<T>(string commandText, params Object[] parameters)

        {

            using (DBEntities context = new DBEntities())

            {

                var results = context.Database.SqlQuery<T>(commandText, parameters);

                results.Single();

                return parameters;

            }

        }

1) EF可以执行存储过程

2)EF可以返回非DB实体 

 

你可能感兴趣的:(framework)