📜  如何从查询c#代码示例中选择类对象

📅  最后修改于: 2022-03-11 14:48:42.949000             🧑  作者: Mango

代码示例1
class ProjectInfo
{
   public string Name {get; set; }
   public long Id {get; set; }
}

public List GetProjectForCombo()
{
    using (MyDataContext db = new MyDataContext (DBHelper.GetConnectionString()))
    {
        var query = from pro in db.Projects
                    select new ProjectInfo(){ Name = pro.ProjectName, Id = pro.ProjectId };

        return query.ToList();
    }
}