asp.net EntityFramework 执行sql top n 错误

应该用()小括号把 n给括起来,

using (var context = new NewContext())
            {
                var sql = @"select top ({0}) * from [News] where ChartRoomId ={1} and IsActive=1 order by id asc";
                var list = context.Database.SqlQuery(sql,top,roomId).ToList();
                return list;
            }

你可能感兴趣的:(Entities)