本文整理汇总了C#中BsonArray.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# BsonArray.FirstOrDefault方法的具体用法?C# BsonArray.FirstOrDefault怎么用?C# BsonArray.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonArray
的用法示例。
在下文中一共展示了BsonArray.FirstOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseResult
private void ParseResult(BsonArray resultArray, QupidQuery query, AggregateResult results)
{
var firstDoc = resultArray.FirstOrDefault();
if (firstDoc == null)
return;
var collectionSelectProperties = query.SelectProperties.Properties
.Where(p => p.Collection.Equals(query.CollectionName, StringComparison.OrdinalIgnoreCase))
.ToList();
results.Columns = collectionSelectProperties.Select(s => !s.IsAggregate? s.Path:s.Alias).ToList();
var shortList = collectionSelectProperties.Select(s => !s.IsAggregate? s.AnalyzedName: s.Alias).ToList();
//TODO: I dont love this because it feels like a double conversion since we convert the _id back to its full name
//later - but it is a pretty cheap call
if (query.GroupByClause != null)
{
//change the select property for the group by to _id so it will match mongo results
shortList = shortList.Select(s => s.Equals(query.GroupByClause.AggregateByProperty.AnalyzedName) ? "_id" : s).ToList();
}
foreach (var curVal in resultArray)
{
var curDoc = curVal.AsBsonDocument;
var row = shortList.Select(col => ExtractColumnValue(curDoc, col)).ToList();
results.Rows.Add(row);
}
}
示例2: In
static bool In(BsonDocument document, string name, BsonArray value)
{
foreach (var data in document.GetNestedValues(name))
{
if (data.BsonType != BsonType.Array)
if (value.FirstOrDefault(x => data.EqualsOrMatches(x)) != null)
return true;
else
continue;
foreach (var it in data.AsBsonArray)
if (value.FirstOrDefault(x => it.EqualsOrMatches(x)) != null)
return true;
}
return false;
}