Return list using select new in LINQ

后端 未结 9 1593
温柔的废话
温柔的废话 2020-11-29 01:59

This is my method which gives me error.

public List GetProjectForCombo()
{
    using (MyDataContext db = new MyDataContext (DBHelper.GetConnect         


        
9条回答
  •  既然无缘
    2020-11-29 02:11

    You're creating a new type of object therefore it's anonymous. You can return a dynamic.

    public dynamic GetProjectForCombo()
    {
        using (MyDataContext db = new MyDataContext (DBHelper.GetConnectionString()))
        {
            var query = from pro in db.Projects
                    select new { pro.ProjectName, pro.ProjectId };
    
            return query.ToList();
        }
    }
    

提交回复
热议问题