型号:
public class WorkSheetModel
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string Name { get; set; }
public string Date_Created { get; set; }
}
收集:
{
"_id" : ObjectId("5510323a50ef4e04a0404815"),
"Name" : "Example",
"Date_Created" : "Sunday, 19 March 2015 01:10 PM"
}
检索数据
public WorkSheetModel getWorkSheets(WorkSheetModel oModel)
{
var worksheet = _db.GetCollection<WorkSheetModel>("WorkSheet");
oModel.SortBy="Date_Created";
workSheetCursor = worksheet.Find(_query).SetSortOrder(SortBy.Ascending(oModel.SortBy)).SetLimit(oModel.ItemsPerPage).SetSkip(oModel.ItemsPerPage * (oModel.PageNo - 1));
oModel.WorkSheetList = new List<WorkSheetModel>();
foreach (WorkSheetModel _worksheet in workSheetCursor)
{
oModel.WorkSheetList.Add(_worksheet);
}
}
在我的收藏中,&#34; Date_Created&#34; 字段的类型为&#34;字符串&#34; ,其中包含日期。现在我想从这个集合中检索数据,按照&#34; Date_Created&#34;的升序排序,但是&#34; Date_Created&#34; field是string类型,按字母排列的顺序检索数据&#34; Date_Created&#34;。
是否可以按字段&#34; Date_Created&#34; 的排序顺序检索数据而不更改字段数据类型?