• 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;
            }
    
  • 相关阅读:
    hdu 6201 dfs
    Oulipo POJ
    Kitchen Measurements UVALive
    Surf Gym
    hoj 13969 Racing Gems
    分块
    分块学习资料
    Jam's problem again HDU
    树的点分治
    Census UVA
  • 原文地址:https://www.cnblogs.com/objectnull/p/13492152.html
Copyright © 2020-2023  润新知