そのため、クエリが返す一連のレコードからランダムなレコードを選択できる必要があります。結果がどのコンテナに表示されるかわからないため、これを行う方法を理解するのに問題があります。データベースの永続化にもEntitySpacesを使用しているため、DBの対話性のほとんどはそこから来ています。
問題が発生している疑似コードを使用して、これを行うことになっているメソッドを以下に貼り付けました。
protected void btnChoose_Click(object sender, EventArgs e)
{
DateTime? dateFrom = null;
DateTime? dateTo = null;
if (!string.IsNullOrWhiteSpace(dtDateTo.Text))
{
dateFrom = dtDateFrom.Text.ToDateTime().Value;
}
if (!string.IsNullOrWhiteSpace(dtDateTo.Text))
{
dateTo = dtDateTo.Text.ToDateTime().Value.EndOfDay();
}
EmployeeRecognitionCollection erc = EmployeeRecognitionCollection.GetAllCards(dateFrom, dateTo, null, null);
--> I need to figure out what 'erc' actually is so I can figure out how to use Random() appropriately
--> I've already verified that erc ends up containing the records that match the criteria in the query (in this case it's just a date range)
}
助けていただければ幸いです。EntitySpacesを使用しているため、この時点でGoogleに何を求めているのかさえわかりません.
ありがとうございました。
アップデート:
だからここに私がこれまでに思いついたものがあります。問題はif
、コレクション内にこれらに対応する値があるはずであることがわかっているときに、ステートメントが false として評価されることです。
EmployeeRecognitionCollection erc = EmployeeRecognitionCollection.GetAllCards(dateFrom, dateTo, null, null);
int minRecords = 0;
int maxRecords = 0;
if (erc[0].ToInteger().HasValue)
{
minRecords = erc[0].ToInteger().Value;
}
if (erc[erc.Count() - 1].ToInteger().HasValue)
{
maxRecords = erc[erc.Count() -1].ToInteger().Value;
}
Random r = new Random();
int winner = r.Next(minRecords, maxRecords);
EmployeeRecognition er = erc[winner];
何か案は?