LINQ获取某个表中的部分字段值


我有个新闻表

id,title,body,createtime,author,click

使用ef4.1 仅仅读取 id,title,createtime 并显示在页面上。

 

 

 public static List<NewInfo> GetHotNews()
        {
            List<NewInfo> list;
            list = (from n in db.NewInfoes
                    where n.IsTop == 1
                    orderby n.PublishTime descending
                    select new
                    {
                        Title = n.Title,
                        NewID = n.NewID,
                        PublishTime = n.PublishTime
                    }).ToList();
            return list;
        }
改为

 

 

public static List<NewInfo> GetHotNews()
        {
            List<NewInfo> list;
            list = (from n in db.NewInfoes
                    where n.IsTop == 1
                    orderby n.PublishTime descending
                   
       .Select(n => new NewInfo
                    {
                        Title = n.Title,
                        NewID = n.NewID,
                        PublishTime = n.PublishTime
                    });
            return list;
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM