日期:2014-05-20  浏览次数:20742 次

求翻译一个 sql为linq
求翻译下面这个entity sql 翻译为 linq to entity
下面这是我自己写的多条件查询,linq怎么实现这种啊

   public IEnumerable<Tfunction> GetTfunctionListByRole(IList<int> list)
       {
           using (MyHanMeErDunDbContext db = new MyHanMeErDunDbContext())
           {
               string sql = "select funcName from Tfunction where ";             
               for (int i = 0; i < list.Count; i++)
               {
                   if (i == 0)                  
                       sql += "funcNo=" + list[0];                
                   else
                       sql += " or funcNo=" + list[i];
               }
               var cmd = db.Database.Connection.CreateCommand();
               db.Database.Connection.Open();
               cmd.CommandText = sql;
               List<Tfunction> fslist = new List<Tfunction>();
               using (var reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
               {
                   while (reader.Read())
                   {
                       Tfunction ts = new Tfunction();                 
                       ts.funcName = reader["funcName"].ToString();
                       fslist.Add(ts);
                   }
                   reader.Close();