I have the following query that selects specific columns from the table and construct DTO. Since i only need certain columns i am not retrieving all the columns from database. In the same method i would also like to update one specific column in retrived Entity
and save entity to database before i return the result.
Entities
public class Client
{
public int ClientID { get; set; }
public string UploadPath { get; set; }
public IEnumerable<Batch> Batches { get; set; }
}
public class Batch
{
public int BatchID { get; set; }
public int StatusID { get; set; }
}
DTO
public class ClientDTO
{
public int ClientID { get; set; }
public string UploadPath { get; set; }
public IEnumerable<Batch> Batches { get; set;}
}
public class BatchDTO
{
public int BatchID { get; set; }
public int StatusID { get; set; }
}
Method
public async Task<IEnumerable<ClientDTO>> GetData()
{
var query = from r in _dbcontext.Clients
select new ClientDTO()
{
ClientID = r.ClientID,
UploadPath = r.UploadPath,
Batches = from r1 in r.Batches
select new BatchDTO()
{
BatchID = r1.BatchID,
StatusID = r1.StatusID
}
};
var result = await query.ToListAsync().ConfigureAwait(false);
// before returning the result i want to update StatusID column in `Batch` entity.
// How do i do that since result is not entity?
return result;
}