public int Queue()
{
using (Entities server = new Entities())
{
var ServerId1 = (from serverID in server.AppPM_Patches
where serverID.PatchStatus == "NotStarted" && serverID.ServerId == 1
select serverID.ServerId).Count();
var ServerId2 = (from serverID in server.AppPM_Patches
where serverID.PatchStatus == "NotStarted" && serverID.ServerId == 2
select serverID.ServerId).Count();
var ServerId3 = (from serverID in server.AppPM_Patches
where serverID.PatchStatus == "NotStarted" && serverID.ServerId == 3
select serverID.ServerId).Count();
if (ServerId1 == 0 && ServerId2 == 0 && ServerId3 == 0)
{
return ServerId1;//Convert.ToInt32(ServerId1);
}
else if (ServerId1 == 1 && ServerId2 == 0 && ServerId3 == 0)
{
return ServerId2;
}
else if (ServerId1 == 1 && ServerId2 == 1 && ServerId3 == 0)
{
return ServerId3;
}
else if (ServerId1 > ServerId2 && ServerId1 > ServerId3)
{
if (ServerId2 > ServerId3)
{
return ServerId3;
}
else
{
return ServerId2;
}
}
else if (ServerId2 > ServerId3 && ServerId2 > ServerId1)
{
if (ServerId1 > ServerId3)
{
return ServerId3;
}
else
{
return ServerId1;
}
}
else if (ServerId3 > ServerId1 && ServerId3 > ServerId2)
{
if (ServerId1 > ServerId2)
{
return ServerId2;
}
else
{
return ServerId1;
}
}
else if (ServerId1 == ServerId2 && ServerId2 == ServerId3 && ServerId1 == ServerId3)
{
return ServerId1;
}
else if (ServerId1 == ServerId2 && ServerId1 > ServerId3 && ServerId2 > ServerId3)
{
return ServerId3;
}
else if (ServerId2 == ServerId3 && ServerId2 > ServerId1 && ServerId3 > ServerId1)
{
return ServerId1;
}
else if (ServerId1 == ServerId3 && ServerId1 > ServerId2 && ServerId1 > ServerId3)
{
return ServerId1;
}
}
}
我在方法中得到錯誤(並非所有的代碼路徑都返回一個值)。這個方法按照我的定義返回一個int值。但不知道爲什麼這個錯誤發生,即使我已經返回一個int值。有人能幫我嗎?不是所有的代碼路徑都在c#中返回一個值#
我會嘗試這個SQL的等效代碼:BY服務器ID ORDER BY COUNT(X),ServerID''... GROUP和拿第一記錄,因爲當你添加ServerID = 4,5,... n時,你所擁有的將會變得糟糕。 –
+1以反擊投票。提出一個真正的問題沒有錯。 – ericosg