never mind, ignore that. I just tried to see if the product returns any attribute of type entity collection but it didn't. I would suggest to try the same code in console app and debug to find the issue.
Your modified code for console app-
=====================
public void GetProducts()
{
using (service = new OrganizationServiceProxy(new Uri(_organizationURI), null, _credential, null))
{
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' >
<entity name = 'product' >
<all-attributes/>
</entity>
</fetch>";
var allProducts = service.RetrieveMultiple(new FetchExpression(fetchXml));
foreach (var prod in allProducts.Entities)
{
List<string> ignoreAttributes = new List<string>() { "productid", "productnumber", "statecode", "statuscode" };
Entity clonedProduct = Clone(prod, new Entity("product"), ignoreAttributes);
service.Create(clonedProduct);
}
}
}
private Entity Clone(Entity source, Entity cloned, List<string> ignoreAttributes)
{
foreach (var attribute in source.Attributes)
{
string attributeName = attribute.Key;
object attributeValue = attribute.Value;
if (ignoreAttributes.Contains(attributeName)) continue;
cloned[attributeName] = attributeValue;
}
return cloned;
}
==============