Topics: CAB & Smart Client Software Factory
Feb 16, 2007 at 7:59 AM
Hi guys!

I've a little problem. I need to translate a Service Entity to my Business Entity with the IEntityTranslatorService, but the problem is that into this Service Entity, has references to other service entities which need to be translated too, i mean. nested traslators.

How can I reference the IEntityTranslatorService from a translator?? is it possible or i'm doing something wrong??

Feb 16, 2007 at 2:16 PM
No, I think that is not possible.

Note: I will call “EntityA” the entity that contains the child, “EntityB”

I suggest you the following options:

1.Inside the translator of “EntityA” you can directly translate “EntityB” as it is in the “Account Translator” of the “BankBranchWorkbench” application:

public class AccountTranslator : EntityMapperTranslator<GlobalBank.Infrastructure.Interface.BusinessEntities.Account, accountType>
protected override accountType BusinessToService(IEntityTranslatorService service, GlobalBank.Infrastructure.Interface.BusinessEntities.Account value)

accountType result = new accountType();
result.accountNumber = value.AccountNumber;
result.accountType1 = new accountTypeType();
result.accountType1.type = value.AccountType.ToString();
result.balance = (decimal)value.Balance;
result.customerId = value.CustomerId;
result.dateOpened = value.DateOpened;
result.interestRate = value.InterestRate;
result.lastTransactionAt = value.LastTransactionDate;
return result;

2. Inside the translator of “EntityA” you can create 2 private methods (1 for BusinessToService, the other for ServiceToBusiness) that encapsulate what was mentioned done option 1 and call them from BusinessToService or SericeToBusiness method as it corresponds.
This could be an example:

private EntityBBussinessType TranslateEntityBToBussines (EntityBserviceType entBservice)
EntityBBussinessType result = new EntityBBussinessType();
//Do assignation/translation of Entity from Service to Business
Return EntityBBussinessType ;

3. You can create a new translator (EntityBTranslator) that implements IEntityTranslator interface and call it from “EntityATranslator” as follows:


protected override EntityBServiceType BusinessToService(IEntityTranslatorService service, BusinessEntities.EntityB value)
//Do assignation/translation of Entity from Business to Service

You should also do the same with ServiceToBussiness to correctly implement IEntityTranslator Interface.


protected override EntityAServiceType BusinessToService(IEntityTranslatorService service, BusinessEntities.EntityA value)
EntityATypeService result = new EntityATypeService();
result.EntityB = EntityBTranslator.BussinessToService(service, value.EntityB);
//Continue translation of EntityA
Return result;

I hope this helps you.

Jonathan Menasches

Feb 19, 2007 at 6:04 AM
Hello jonathan.

I had this idea in my head, but I want to now it if was possible what I told, i see it's impossible so, i do ir that way.

Thanks a lot for your help.