日期:2014-05-20 浏览次数:20725 次
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();
fs.newsid = Convert.ToInt32(reader["id"]);
fs.newsTitle = reader["newstitle"].ToString();
fs.class_ename = reader["classename"].ToString();
fs.class_type = reader["type_new"].ToString();
fslist.Add(fs);
}
reader.Close();
}
db.Database.Connection.Close();
return fslist;