1. 程式人生 > >LINQ能不能用系列(二)LINQ to SQL 效率比對

LINQ能不能用系列(二)LINQ to SQL 效率比對

複製程式碼
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 = new
List<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 } }
複製程式碼