这是我的桌子类:
Error The best overloaded method match for 'System.Windows.Forms.TextBoxBase.AppendText(string)' has some invalid arguments
Error Argument 1: cannot convert from 'System.Collections.Generic.List<string>' to 'string'
在这里,我想要获取每public partial class Dept_Emp
{
public int Id { get; set; }
public string F_Name { get; set; }
public string L_Name { get; set; }
public string Gender { get; set; }
public string DeprtmentName { get; set; }
public Nullable<decimal> Sal { get; set; }
}
Sal
的总和。我写了一个简单的Linq查询,但它在DepartmentName
抛出了上述错误。
Linq:
g.Sum(x => x.Sal)
答案 0 :(得分:0)
但如果我将上面的查询写为
IEnumarable<Dept_Emp> GetData(){ > -------Some ---Code --- }
那么什么是返回值
然后你需要返回Dept_Emp
个实例而不是匿名类型:
return db.Dept_Emp.GroupBy(d => d.DeprtmentName)
.Select(g => new Dept_Emp
{
Id = g.First().Id,
F_Name = g.First().F_Name,
L_Name = g.First().L_Name,
Gender = g.First().Gender,
DeprtmentName = g.Key,
Sal = g.Sum(x => x.Sal)
});