开发者

add dummy column in LINQ fetch query

开发者 https://www.devze.com 2023-02-26 15:06 出处:网络
How to return the List in LINQ query while adding a dummy column, How to return qry as LIST. public static List<MSDNMagazine.emp> FetchEmp()

How to return the List in LINQ query while adding a dummy column, How to return qry as LIST.

public static List<MSDNMagazine.emp> FetchEmp() 
{
    try
    {
        MSDNMagazine.JsonDataContext context = new MSDNMagazine.JsonDataContext(); 
        var qry = from p in context.emps 
        select开发者_如何学C new
        {
            emp_cod = p.emp_cod,
            emp_nam = p.emp_nam,
            test = "0"
        };
        return (List< >)qry; 
    }
    catch (Exception ex) 
    {
        throw ex; 
    }
}


select new emp //the name of the class
{
    emp_cod = p.emp_cod,
    emp_nam = p.emp_nam,
    test = "0"
};
return qry.ToList(); 


Use the ToList() Extension method.

return qry.ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号