Код: Выделить всё
[BsonIgnoreExtraElements]
public class Author
{
[BsonId][BsonRepresentation(BsonType.ObjectId)] public ObjectId _id { get; set; }
[BsonElement("first")] public string? first { get; set; }
[BsonElement("last")] public string? last { get; set; }
[BsonElement("author_id")] public BsonInt32? author_id { get; set; }
[BsonElement("FullName")][BsonIgnoreIfNull] public string? FullName { get; set; }
}
[BsonIgnoreExtraElements]
public class Book
{
[BsonId][BsonRepresentation(BsonType.ObjectId)] public ObjectId _id { get; set; }
[BsonElement("title")] public string? title { get; set; }
[BsonElement("title_id")] public BsonInt32? title_id { get; set; }
[BsonElement("author")] public string? author { get; set; }
[BsonElement("issue_date")] public string? issue_date { get; set; }
[BsonElement("return_date")] public string? return_date { get; set; }
}
Код: Выделить всё
public async Task GetPopular()
{
IMongoQueryable? query = (from book in booksCollection.AsQueryable()
group book by book.author into g
let lastBook = g.OrderByDescending(b => b.return_date).FirstOrDefault()
select new Popular
{
Author = g.Key,
Count = g.Count(),
ReturnDate = lastBook.return_date,
Title = lastBook.title
}).OrderByDescending(g => g.Count).ThenBy(g => g.Author).Take(10);
List? popular = await query.ToListAsync();
return popular;
}
Код: Выделить всё
**MongoDB.Driver.Linq.Linq3Implementation.Ast.Optimizers.AstGroupingPipelineOptimizer+UnableToRemoveReferenceToElementsException:**
'Exception of type 'MongoDB.Driver.Linq.Linq3Implementation.Ast.Optimizers.AstGroupingPipelineOptimizer+UnableToRemoveReferenceToElementsException' was thrown.'
Подробнее здесь: https://stackoverflow.com/questions/790 ... on-android
Мобильная версия