如何使用LINQ从表中选择第一行 [英] How to select first row from table using LINQ

查看:108
本文介绍了如何使用LINQ从表中选择第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要从特定列中选择第一行。



下面是我的代码。我不知道如何完成这件事。



Hi,

I need to select the first row from a particular column.

Below is my code. I dont know how to get this done.

public static List<OverallCompliance> load()
        {
            List<OverallCompliance> _load = new List<OverallCompliance>();
            try
            {
                using (Entities1 entity = new Entities1())
                {
                    _load = entity.mssp_fw_prod_compliance
                        .Select(s => new { s.PRODUCT_NAME })
                        .AsEnumerable()
                        .Select(x => new OverallCompliance
                        {
                            prod_name = x.PRODUCT_NAME
                        }).ToList();
                }
            }
            catch (Exception ex)
            { }
            return _load;
        }





请帮忙。在此先感谢



Please help. Thanks in advance

推荐答案

访问此处...

http://stackoverflow.com/questions/1512471/linq-select-first-row [ ^ ]
visit here...
http://stackoverflow.com/questions/1512471/linq-select-first-row[^]


您可以尝试如下所示。我还没有检查它是否正常工作...



You can try like this as below. i have not checked whether its working or not...

public static List<overallcompliance> load()
        {
            List<overallcompliance> _load = new List<overallcompliance>();
            try
            {
                using (Entities1 entity = new Entities1())
                {
                    _load = entity.mssp_fw_prod_compliance.Select(s => new { s.PRODUCT_NAME })
.AsEnumerable()
.Select(x => new OverallCompliance
{
    prod_name = x.PRODUCT_NAME
}).ToList<overallcompliance>().FirstOrDefault();

                }
            }
            catch (Exception ex)
            { }
            return _load;
        }


这篇关于如何使用LINQ从表中选择第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆