I have 2 models, one for database and one is DTO
Here is the database model
public class Tenancy : FullAuditedEntity, IMustHaveTenant
{
public DateTime? TenancyStartDate { get; set; }
public DateTime? TenancyEndDate { get; set; }
public DateTime? RenewalDate { get; set; }
public DateTime? ContractEndDate { get; set; }
public DateTime? ReminderNotificationDate { get; set; }
public ContractTermTimeUnit ContractTermTimeUnit { get; set; }
public int ContractTermLength { get; set; }
public TenancyStatus Status { get; set; }
public int PropertyId { get; set; }
public int ContractTypeId { get; set; }
public int TenantId { get; set; }
public int? TenancyChargeId { get; set; }
[ForeignKey("ContractTypeId")]
public ContractType ContractType { get; set; }
[ForeignKey("PropertyId")]
public Property Property { get; set; }
[ForeignKey("TenancyChargeId")]
public TenancyCharge TenancyCharge { get; set; }
public int? FrequencyTypeId { get; set; }
[ForeignKey("FrequencyTypeId")]
public FrequencyType Frequencytype { get; set; }
public decimal RentlValue { get; set; }
public decimal DepositValue { get; set; }
public int? RentFrequencyTypeId { get; set; }
[ForeignKey("RentFrequencyTypeId")]
public RentFrequencyType RentFrequencyType { get; set; }
public virtual ICollection<PropertyTenantTenancy> PropertyTenantTenancies { get; set; }
}
and here is DTO
public class TenancyDto : EntityDto<int?>
{
public DateTime? TenancyStartDate { get; set; }
public DateTime? TenancyEndDate { get; set; }
public DateTime? RenewalDate { get; set; }
public DateTime? ReminderNotificationDate { get; set; }
public ContractTermTimeUnit ContractTermTimeUnit { get; set; }
public int ContractTermLength { get; set; }
public virtual DateTime? ContractEndDate { get; set; }
public TenancyStatus Status { get; set; }
public int PropertyId { get; set; }
public int PropertyTenantId { get; set; }
public decimal RentValue { get; set; }
public decimal DepositValue { get; set; }
public int? TenantId { get; set; }
public int ContractTypeId { get; set; }
public IList<TenancyTenantDto> Tenants { get; set; }
}
I make saving like this
public async Task CreateOrEditTenancy(TenancyDto input)
{
var tenantId = AbpSession.TenantId;
await CheckTenancyConflictsAsync(input);
if (input.Id.HasValue)
{
var tenancy = await _tenancyRepository.GetAsync(input.Id.Value);
await _tenancyRepository.UpdateAsync(ObjectMapper.Map(input, tenancy));
}
else
{
if (tenantId == null)
{
throw new UserFriendlyException(L("FunctionalityIsNotAvailable"));
}
input.TenantId = (int)tenantId;
input.Status = TenancyStatus.Draft;
await _tenancyRepository.InsertAsync(ObjectMapper.Map<Tenancy>(input));
}
}
and mapping like this
configuration.CreateMap<TenancyDto, Tenancy>()
.ForMember(x => x.PropertyTenantTenancies, opt => opt.MapFrom(aa => aa.Tenants));
all works, except this stuff public IList<TenancyTenantDto> Tenants { get; set; }
I have this list in input. I have no errors. Just empty table at the result . It seems it doesn't map. Where can be my problem?