且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用LINQ从表中选择第一行

更新时间:2023-02-05 17:01:04

访问此处...

http://***.com/questions/1512471/linq-select-first-row [ ^ ]
visit here...
http://***.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;
        }