Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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

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

C#
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
Posted

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

SQL
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;
        }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900