Closed
Description
Following the next example: when using ProjectToType on a queryable Mapster is eager loading the data "SomeOtherEntity" and ignores the "include take(1)".
class SomeEntity
{
private ICollection<SomeOtherEntity> MyList { get; set; }
}
class SomeOtherEntity
{
private SomeEntity myEntity { get; set; }
}
class MyModel
{
private ICollection<SomeOtherEntity> MyList { get; set; }
}
class MyOtherModel
{
private MyModel myEntity { get; set; }
}
await _dbContext.SomeEntity
.AsNoTracking()
.Where(x => x.IsActive == isActive)
.Include(x =>
x.SomeOtherEntity
.OrderByDescending(p => p.Date)
.Take(1))
.ProjectToType<MyModel>()
.ToListAsync(cancellationToken);
Mapping data this way: works fine!
var data = await _dbContext.SomeEntity
.AsNoTracking()
.Where(x => x.IsActive == isActive)
.Include(x =>
x.SomeOtherEntity
.OrderByDescending(p => p.Date)
.Take(1))
.ToListAsync(cancellationToken);
return data.Adapt<List<SomeModel>>();
Metadata
Metadata
Assignees
Labels
No labels