我有以下情形中,我試圖用分組方法無法隱式轉換類型「匿名類型#1 []」到「INT []」
//Gets MulitCourseIds from db of selected CourseIds
int[] _hasListCourseIds = (from mcd in _db.MultiCourseDetails
where _lstCourseIds.Contains(mcd.CourseId.Value)
group mcd.MultiCourseId by mcd.MultiCourseId into g
select new { multiCourseId = g.Key }).ToArray();
************ error is occuring here**********
if (_hasListCourseIds.Count > 0)
{
//Checks the count of courseIds from the db and selected courseIds
foreach (var _multiCourseId in _hasListCourseIds)
{
var _courseCount = _db.MultiCourseDetails
.Where(x => x.MultiCourseId == _multiCourseId)
.Count();
if (_courseCount == _lstCourseIds.Count)
{
return true;
}
}
我得到的錯誤,以獲取數據庫信息
無法隱式轉換類型 '匿名類型#1 []' 到 'INT []'
提高代碼的任何建議,也邀請了..
如果你不關心這個類型,使用'var'而不是'int []' – singsuyash
對不起,隊友轉換是必需的,因爲我用它來檢查內部循環,如問題所示.. – ksg
'g。 Key'已經是'int'了嗎?所以匿名類型也會有一個'int' – singsuyash