Код: Выделить всё
public class User
{
public string FullName { get; set; }
public string DomainEmail { get; set; }
}
public class UserDto
{
public string Name { get; set; }
public string Email { get; set; }
}
Код: Выделить всё
var matchStage = new BsonDocument(Match, new BsonDocument
{
{ nameof(User.FullName), new BsonDocument(Eq, "Foo bar") }
});
var pipeline = new[] { matchStage };
var result = await _collection.Aggregate(pipeline).ToListAsync();
return result;
Код: Выделить всё
var projection = Builders.Projection.Expression(m => new UserDto
{
Name = m.FullName,
Email = m.DomainEmail
});
var result = await _collection
.Aggregate(pipeline)
.Project(projection) // This doesn't work
.ToListAsync();
return result;
Код: Выделить всё
CreateMap()
.ForMember(u => u.Name, opts => opts.MapFrom(u => u.FullName))
.ForMember(u => u.Email, opts => opts.MapFrom(u => u.DomainEmail));
- .NET 8
- Драйвер MongoDB версии 2.24
Подробнее здесь: https://stackoverflow.com/questions/782 ... h-pipeline
Мобильная версия