Base solution for your next web application
Open Closed

Multi-lingual Entity & application service generated by RAD #5538


User avatar
0
expertit created

Hello,

I need some help about the implementation of multi-lingual entities and the RAD tool.

As example, I have three entities :

  • Person
  • PersonTitleType
  • PersonTitleTypeTranslation

concerning the query generated by the RAD tool how to adapt these queries in order to be sure that the Translations collection property is loaded, like :

var filteredEitPeople = _eitPersonRepository.GetAll()
						.WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false  || e.KeyName.Contains(input.Filter) || e.FirstName.Contains(input.Filter) || e.LastName.Contains(input.Filter) || e.Email.Contains(input.Filter) || e.Phone.Contains(input.Filter) || e.MobilePhone.Contains(input.Filter))
						.WhereIf(!string.IsNullOrWhiteSpace(input.KeyNameFilter),  e => e.KeyName.ToLower() == input.KeyNameFilter.ToLower().Trim())
						.WhereIf(!string.IsNullOrWhiteSpace(input.FirstNameFilter),  e => e.FirstName.ToLower() == input.FirstNameFilter.ToLower().Trim())
						.WhereIf(!string.IsNullOrWhiteSpace(input.LastNameFilter),  e => e.LastName.ToLower() == input.LastNameFilter.ToLower().Trim())
						.WhereIf(!string.IsNullOrWhiteSpace(input.EmailFilter),  e => e.Email.ToLower() == input.EmailFilter.ToLower().Trim())
						.WhereIf(!string.IsNullOrWhiteSpace(input.PhoneFilter),  e => e.Phone.ToLower() == input.PhoneFilter.ToLower().Trim())
						.WhereIf(!string.IsNullOrWhiteSpace(input.MobilePhoneFilter),  e => e.MobilePhone.ToLower() == input.MobilePhoneFilter.ToLower().Trim());


            var query = (from o in filteredEitPeople
                         join o1 in _eitPersonGenderTypeRepository.GetAll() on o.EitPersonGenderTypeId equals o1.Id into j1
                         from s1 in j1.DefaultIfEmpty()
                         join o2 in _eitPersonTitleTypeRepository.GetAll() on o.EitPersonTitleTypeId equals o2.Id into j2
                         from s2 in j2.DefaultIfEmpty()

                         select new GetEitPersonForView() { EitPerson = ObjectMapper.Map<EitPersonDto>(o)
                         , EitPersonGenderTypeName = s1 == null ? "" : s1.KeyName // TODO AJA :  s1.DisplayName.ToString()
					, EitPersonTitleTypeName = s2 == null ? "" : s2.Name.ToString()
					
						 })
						 
						.WhereIf(!string.IsNullOrWhiteSpace(input.EitPersonGenderTypeNameFilter), e => e.EitPersonGenderTypeName.ToLower() == input.EitPersonGenderTypeNameFilter.ToLower().Trim())
						.WhereIf(!string.IsNullOrWhiteSpace(input.EitPersonTitleTypeNameFilter), e => e.EitPersonTitleTypeName.ToLower() == input.EitPersonTitleTypeNameFilter.ToLower().Trim());

            var totalCount = await query.CountAsync();

            var eitPeople = await query
                .OrderBy(input.Sorting ?? "eitPerson.id asc")
                .PageBy(input)
                .ToListAsync();

            return new PagedResultDto<GetEitPersonForView>(
                totalCount,
                eitPeople
            );

In the "join", I tried

join o2 in _eitPersonTitleTypeRepository.GetAllIncluding(p => p.Translations) on o.EitPersonTitleTypeId equals o2.Id into j2

but, this is not working.

Another question, how to implement the filtering with the Translation values ?

Thanks for your help

Best regards,

Albert


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use LinQ group join as explained here <a class="postlink" href="https://stackoverflow.com/a/15599143/6681451">https://stackoverflow.com/a/15599143/6681451</a>. You can easily filter translations if you use group join and comprehension syntax.