my simple app has 10 tables, each of these tables has same propery "CreatedDate" which is a DateTime prop and as its name says its holding creation date.
Since I'm fetching all the data through DTO's for example if I want to get articles from database I'm mapping it to ArticleDto and returning data to the user.
And I'm doing that all for each 10 classes-entites. And each Dto, (ArticleDto, GroupDto, UserDto, TownDto, AddressDto) all of them now have DateTime property which I'm populating when retrieving data from database..
Is it possible to achieve somehow that this prop is automatically populated ?
This is how I am doing it right now for Towns for example:
public class TownGetDto : DateTimeGetDto
{
public long Id { get; set; }
public string Title { get; set; }
public string ZipCode { get; set; }
public string DialingCode { get; set; }
public long CountryId { get; set; }
}
public class DateTimeGetDto
{
public DateTime CreatedDate { get; set; }
}
public async Task<TownGetDto> GetTownsAsync(CancellationToken cancellationToken)
{
var towns = await _dbContext.Towns
.Select(x => new TownGetDto
{
Id = x.Id,
Title = x.Title,
DialingCode = x.DialingCode,
ZipCode = x.ZipCode,
CountryId = x.CountryId,
CreatedDate = x.CreatedDate // How to get rid of this prop?
})
.ToListAsync(cancellationToken);
return towns;
}
As you can see I am popualting CreatedDate in Select and I'm doing that for all my classes/entities..
Is it possible somehow to fill-populate this prop automatically ?
Thanks everyone,
Cheers