Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我需要有关此I.Score/I.Count的帮助。有一个错误无法隐式转换int?整型_C#_Asp.net - Fatal编程技术网

C# 我需要有关此I.Score/I.Count的帮助。有一个错误无法隐式转换int?整型

C# 我需要有关此I.Score/I.Count的帮助。有一个错误无法隐式转换int?整型,c#,asp.net,C#,Asp.net,看起来在您的模型类ArticleWithCore中,您没有声明属性Score为null,即int?相反,您声明了int。谢谢您修复了它! var v = (from a in dc.Articles join b in dc.ratings on a.ArticleID equals b.ArticleID into bb from b in bb.DefaultIfEmpty() group new { a, b } by new { a.

看起来在您的模型类ArticleWithCore中,您没有声明属性Score为null,即int?相反,您声明了int。

谢谢您修复了它!
var v = (from a in dc.Articles
         join b in dc.ratings on a.ArticleID equals b.ArticleID into bb
         from b in bb.DefaultIfEmpty()
         group new { a, b } by new { a.ArticleID, a.Articletitle } into AA
         select new
         {
             AA.Key.ArticleID,
             AA.Key.Articletitle,
             Score = AA.Sum(a => a.b.Score) == null ? 0 : AA.Sum(a => a.b.Score),
             Count = AA.Count()
         }
         );

List<ArticlewithScore> AWS = new List<ArticlewithScore>();
foreach (var i in v)
{
    AWS.Add(new ArticlewithScore
    {
        ArticleID = i.ArticleID,
        ArticleTitle = i.Articletitle,
        Score = i.Score / i.Count
    });