Can't create translator for collection

Topics: Service Factory Modeling Edition Forum
Nov 15, 2007 at 9:56 PM
I have a business entity with a property that is of the same type as a collection contract type. That is, if my contract is named DataCollContract, then my property in the Business entity is declared as:
DataCollContract _MyColl;

When I go to create a translator, and select the _MyColl property in my business entity, and the DataCollContract type, I get a failure message stating that a possible reason in there are no appropriate getters/setters. Here is the code in my business entity:
private RejectedBallotCollContract _Doodah;
public RejectedBallotCollContract Doodah
{
get
{
return _Doodah;
}
set
{
_Doodah = value;
}
}

How does one generate a "translator" when one is trying to translate from one collection to another?
Nov 20, 2007 at 2:41 PM
The translator doesn't support the "translation" of collections. You need to modify the generated translator in order to add the collection "translation". First you need a translator for the type of the collection (below is a snippet):

public static WCFService1.BusinessEntities.Company TranslateCompanyToCompany(WCFService1.DataContracts.Company from)
{
WCFService1.BusinessEntities.Company to = new WCFService1.BusinessEntities.Company();
to.Name = from.Name;
return to;
}

and then you need to iterate thru the collection and translate each one, below is a code snippet for more detail:

public static WCFService1.BusinessEntities.Person TranslatePersonToPerson(WCFService1.DataContracts.Person from)
{
WCFService1.BusinessEntities.Person to = new WCFService1.BusinessEntities.Person();
to.Name = from.Name;
to.Age = from.Age;

foreach (WCFService1.DataContracts.Company company in from.Companies)
{
to.Companies.Add(TranslateBetweenCompanyAndCompany.TranslateCompanyToCompany(company));
}

return to;
}

Be aware that if you modify the generated translator by hand whenever you modify it using the Guidance Package it will be replaced.

Please let me know if this helped.

Cheers.
Nov 20, 2007 at 5:23 PM
Thanks! I finally decided (before receiving your post) that I would have to do something custom. What's strange is, one side of the "generation" dialog shows the "from" side in detail (from the database side), but the output side is not. Yet they both have the same structure.

I wouldn't do the custom by modifying the generated. First, this was the only data item, and it didn't generate a custom. Second, I would do a a partial, or a subclass of anything generated.

Unfortunately, I've finally given up on using this at all. I couldn't install the data repositry Guidance package, So I did some uninstalls, and ALL the packages are completely hosed. I've repaired VS 2005, but after finally removing Guidance package, and then having to remove the GAX by hand, I can't re-install the latest version of the GAX to re-install the rest of the Guidance package.

I've been using MSFT products since 1994, version 3.x of Windows. This experience with the Guidance packages is absolutely the worst experience I've ever had with anything from MSFT. If they really want people to try/use these, they really need to get their act together on the un/install processes for these packages.