Is it possible to return the EntityCollection and include related records?
For instance, I have this code:
EntityCollection acclist = new EntityCollection();
acclist.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = erf.Id, ["fax"] = 123
});
acclist.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = new Guid("9f31bb4c-9125-ee11-9cbc-000d3ab1669a"), ["fax"] = 321
});
acclist.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = new Guid("a131bb4c-9125-ee11-9cbc-000d3ab1669a"), ["fax"] = 456
});
acclist.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = new Guid("a331bb4c-9125-ee11-9cbc-000d3ab1669a"), ["fax"] = 654
});
EntityCollection acclist2 = new EntityCollection();
acclist2.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = erf.Id,
["fax"] = 777,
["_parentaccountid_value"] = new Guid("a331bb4c-9125-ee11-9cbc-000d3ab1669a"),
["_parentaccountid_value@Microsoft.Dynamics.CRM.associatednavigationproperty"] = "parentaccountid",
["_parentaccountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"] = "account",
["_parentaccountid_value"] = "9f31bb4c-9125-ee11-9cbc-000d3ab1669a"
});
acclist.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = new Guid("a331bb4c-9125-ee11-9cbc-000d3ab1669a"), ["fax"] = 666, ["account_parent_account"] = acclist2
});
string debug = JsonConvert.SerializeObject(acclist);
acclist.Entities.Add(new Entity(Account.EntityLogicalName) {
["accountid"] = new Guid("a331bb4c-9125-ee11-9cbc-000d3ab1669a"), ["fax"] = debug
});
context.OutputParameters["resultArray"] = acclist;
and as a result I get this:
"resultArray": [
{
"@odata.type": "#Microsoft.Dynamics.CRM.account",
"accountid": "d6208772-d545-eb11-a813-0022481eae24",
"fax": 123
},
{
"@odata.type": "#Microsoft.Dynamics.CRM.account",
"accountid": "9f31bb4c-9125-ee11-9cbc-000d3ab1669a",
"fax": 321
},
{
"@odata.type": "#Microsoft.Dynamics.CRM.account",
"accountid": "a131bb4c-9125-ee11-9cbc-000d3ab1669a",
"fax": 456
},
{
"@odata.type": "#Microsoft.Dynamics.CRM.account",
"accountid": "a331bb4c-9125-ee11-9cbc-000d3ab1669a",
"fax": 654
},
{
"@odata.type": "#Microsoft.Dynamics.CRM.account",
"accountid": "a331bb4c-9125-ee11-9cbc-000d3ab1669a",
"fax": 666
},
{
"@odata.type": "#Microsoft.Dynamics.CRM.account",
"accountid": "a331bb4c-9125-ee11-9cbc-000d3ab1669a",
"fax": "{\"Entities\":[{\"LogicalName\":\"account\",\"Id\":\"00000000-0000-0000-0000-000000000000\",\"Attributes\":[{\"Key\":\"accountid\",\"Value\":\"d6208772-d545-eb11-a813-0022481eae24\"},{\"Key\":\"fax\",\"Value\":123}],\"EntityState\":null,\"FormattedValues\":[],\"RelatedEntities\":[],\"RowVersion\":null,\"KeyAttributes\":[]},{\"LogicalName\":\"account\",\"Id\":\"00000000-0000-0000-0000-000000000000\",\"Attributes\":[{\"Key\":\"accountid\",\"Value\":\"9f31bb4c-9125-ee11-9cbc-000d3ab1669a\"},{\"Key\":\"fax\",\"Value\":321}],\"EntityState\":null,\"FormattedValues\":[],\"RelatedEntities\":[],\"RowVersion\":null,\"KeyAttributes\":[]},{\"LogicalName\":\"account\",\"Id\":\"00000000-0000-0000-0000-000000000000\",\"Attributes\":[{\"Key\":\"accountid\",\"Value\":\"a131bb4c-9125-ee11-9cbc-000d3ab1669a\"},{\"Key\":\"fax\",\"Value\":456}],\"EntityState\":null,\"FormattedValues\":[],\"RelatedEntities\":[],\"RowVersion\":null,\"KeyAttributes\":[]},{\"LogicalName\":\"account\",\"Id\":\"00000000-0000-0000-0000-000000000000\",\"Attributes\":[{\"Key\":\"accountid\",\"Value\":\"a331bb4c-9125-ee11-9cbc-000d3ab1669a\"},{\"Key\":\"fax\",\"Value\":654}],\"EntityState\":null,\"FormattedValues\":[],\"RelatedEntities\":[],\"RowVersion\":null,\"KeyAttributes\":[]},{\"LogicalName\":\"account\",\"Id\":\"00000000-0000-0000-0000-000000000000\",\"Attributes\":[{\"Key\":\"accountid\",\"Value\":\"a331bb4c-9125-ee11-9cbc-000d3ab1669a\"},{\"Key\":\"fax\",\"Value\":666},{\"Key\":\"account_parent_account\",\"Value\":{\"Entities\":[{\"LogicalName\":\"account\",\"Id\":\"00000000-0000-0000-0000-000000000000\",\"Attributes\":[{\"Key\":\"accountid\",\"Value\":\"d6208772-d545-eb11-a813-0022481eae24\"},{\"Key\":\"fax\",\"Value\":777},{\"Key\":\"_parentaccountid_value\",\"Value\":\"9f31bb4c-9125-ee11-9cbc-000d3ab1669a\"},{\"Key\":\"_parentaccountid_value@Microsoft.Dynamics.CRM.associatednavigationproperty\",\"Value\":\"parentaccountid\"},{\"Key\":\"_parentaccountid_value@Microsoft.Dynamics.CRM.lookuplogicalname\",\"Value\":\"account\"}],\"EntityState\":null,\"FormattedValues\":[],\"RelatedEntities\":[],\"RowVersion\":null,\"KeyAttributes\":[]}],\"MoreRecords\":false,\"PagingCookie\":null,\"MinActiveRowVersion\":null,\"TotalRecordCount\":0,\"TotalRecordCountLimitExceeded\":false,\"EntityName\":null}}],\"EntityState\":null,\"FormattedValues\":[],\"RelatedEntities\":[],\"RowVersion\":null,\"KeyAttributes\":[]}],\"MoreRecords\":false,\"PagingCookie\":null,\"MinActiveRowVersion\":null,\"TotalRecordCount\":0,\"TotalRecordCountLimitExceeded\":false,\"EntityName\":null}"
}
]
So, in testing this I can see the collection has the data but it doesn't show. I even added those extra fields to the related record.
Is it possible to do this?