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

linq to entity 与 entity sql 性能
一个是用linq to entity写的
一个是entity sql写的
性能杂差别老大呢

linq to entity
100000
00:00:00.8281250 
基本在0.8-1之间

entity sql
100000
00:00:00.3593750 
基本在0.3-0.5之间

都是加载10W条数据



               IEnumerable<HanModel.Models.ViewModel.Fs_NewsOrClass> query = (
                   db.fs_news.OrderByDescending(fn => fn.Click).Join(
                   db.fs_news_Class, fn => fn.ClassID, fc => fc.ClassID, (fn, fc) =>
                  new HanModel.Models.ViewModel.Fs_NewsOrClass
                       {
                           newsid = fn.Id,
                           newsTitle = fn.NewsTitle,
                           class_ename = fc.ClassEName,
                           class_type = fc.Type_New
                       })).Take(100000).ToList();
               return query;

===============================================================
               string sql = "select top 100000  fn.id,fn.newstitle,fc.classename,fc.type_new from fs_news as fn inner join fs_news_class as fc on fn.classid=fc.classid  order by fn.click desc";
               var cmd = db.Database.Connection.CreateCommand();
               db.Database.Connection.Open();
               cmd.CommandText = sql;
               List<HanModel.Models.ViewModel.Fs_NewsOrClass> fslist = new List<HanModel.Models.ViewModel.Fs_NewsOrClass>();
               using (var reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
               {
                   while (reader.Read())
                   {
                       HanModel.Models.ViewModel.Fs_NewsOrClass fs = new HanModel.Models.ViewModel.Fs_NewsOrClass();