0
我正在嘗試使用Lambda或Linq來計算值在我的表的列中出現的次數。計算字段屬性在列中出現的次數
這裏是我的表性能
public class Vote
{
[Key]
public int VoteId { get; set; }
public int CandidateId { get; set; }
public int CategoryId { get; set; }
public string Id { get; set; }
public int ParticipantId { get; set; }
public DateTime datecreated { get; set; }
}
所以在我的控制,我做這個
public ActionResult Index(int? CategoryId, string Id)
{
List<VoteCan> agc = new List<VoteCan>();
if(CategoryId.HasValue)
{
var allcategory = db.Votes.ToList().FindAll(x => (x.CategoryId == CategoryId.Value) && (x.Id == Id)).ToList();
//I want to count how many Candidates are in the Votes table using the candidateId
}
return View();
}
例如,我想有這樣的事情
CandidateNo Count
21358 3
21878 4