如何使用 Linq 对某些属性进行乘法运算和求和
我有同样的问题。我想要学生的计算器分数。我完成了:
var cosrse = from ssh in cn.DB.ScoreSheets
where ssh.CourseID == CourseID
select new
{
Student = ssh.Student.LastName +" "+ ssh.Student.FirstName,
ssh.Student.StudentID, Assignment = ssh.Assignment,
Project = ssh.Project,
ssh.Midterm,
ssh.Endterm,
ssh.Practice,
FinalMatch = ssh.Midterm * 0.2 + ssh.Project * 0.3 +
ssh.Endterm * 0.5 // new a propety FinalMatch
};
我想添加 FinalMatch 列并分配: ssh.Midterm * 0.2 + ssh.Project * 0.3 + ssh.Endterm * 0.5
但我没有得到 FinalMatch 的任何结果。 在这里,我从两个表中进行选择:[Student]、[ScoreSheet] 所有表都有记录。我想输入学生和计算器国际泳联比赛的分数。 期待收到您的解决方案 尊敬的威廉!
I has same a problem. which I want caculator score for student. I done:
var cosrse = from ssh in cn.DB.ScoreSheets
where ssh.CourseID == CourseID
select new
{
Student = ssh.Student.LastName +" "+ ssh.Student.FirstName,
ssh.Student.StudentID, Assignment = ssh.Assignment,
Project = ssh.Project,
ssh.Midterm,
ssh.Endterm,
ssh.Practice,
FinalMatch = ssh.Midterm * 0.2 + ssh.Project * 0.3 +
ssh.Endterm * 0.5 // new a propety FinalMatch
};
I want to add column FinalMatch and assign : ssh.Midterm * 0.2 + ssh.Project * 0.3 + ssh.Endterm * 0.5
But I don't get any result for FinalMatch.
In here, I has select from two table: [Student],[ScoreSheet] all table have recors. I want to enter score for student and caculater fina match.
Forward to receiving your solutions
Respectfully william!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将其转换为 SQL,当一个或多个值为
null
时,您可能会得到一些令人讨厌的 0(零)结果。If this is translated to SQL, you can get some nasty 0 (zero) results when one or more values are
null
.