LINQ能不能用系列(二)LINQ to SQL 效率比對
阿新 • • 發佈:2019-02-03
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace LINQProject { /// <summary> /// 遊戲資訊業務處理類(LINQ TO SQL 效率測試用) /// 王磊(Stone) /// 2012.05.18 /// </summary> public class GameInfoBLL { #region 根據遊戲名稱模糊查詢 ///<summary> /// 根據遊戲名稱模糊查詢 /// </summary> /// <param name="name">遊戲名稱呢個</param> /// <returns>List<GameInfoModel></returns> public static List<GameInfoModel> GetGameInfoByGname(string name) { List<GameInfoModel> list = newList<GameInfoModel>(1000000); string sql = "select * from gameinfo where gamename like @gamename"; SqlDataReader dr = null; try { using (dr = DBHelper.GetSqlDataReaderBySql(sql, new SqlParameter[]{ new SqlParameter("@gamename","%"+name+"%") })) { GameInfoModel game = new GameInfoModel(); while (dr.Read()) { game.gid = (int)dr["gid"]; game.gamename = (string)dr["gamename"]; game.createtime = (DateTime)dr["createtime"]; game.content = (string)dr["content"]; game.gametype = (int)dr["gametype"]; list.Add(game); } } } catch (Exception ex) { if (null != dr && !dr.IsClosed) { dr.Close(); } throw ex; } return list; } #endregion } }