This repository has been archived by the owner on Jun 16, 2024. It is now read-only.
Query on associatedentitytypecode should work with both Entity Name and ObjectTypeCode #569
Labels
Milestone
Describe the bug
When you query the documenttemplate table in CRM, and you add a filter on the 'associatedentitytypecode' column, you can pass this either as an integer (the objecttypecode) or as a string (the table name). When you perform the same query against fakeXrmEasy, it fails if you pass in the object type code, as it tries to perform the string method 'ToLowerInvariant' on the integer.
This is the error:
Method 'System.String ToLowerInvariant()' declared on type 'System.String' cannot be called with instance of type 'System.Int32'
To Reproduce
Here's code that will work in Dynamics 365 online (sorry couldn't get github to format it better):
void Main()
{
IOrganizationService service = MyExtensions.ConnectToCrm(MyExtensions.Environments.BLAH_DEV);
GetTemplateWithEntityName(service).Dump("Query with entity Name");
GetTemplateWithEntityTypeCode(service).Dump("Query with ObjectTypeCode");
}
Guid GetTemplateWithEntityTypeCode(IOrganizationService service)
{
QueryExpression query = new QueryExpression("documenttemplate");
query.Criteria.AddCondition("name", ConditionOperator.Equal, "Order Summary");
//query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, "salesorder");
query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, 1088);
}
Guid GetTemplateWithEntityName(IOrganizationService service)
{
QueryExpression query = new QueryExpression("documenttemplate");
query.Criteria.AddCondition("name", ConditionOperator.Equal, "Order Summary");
query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, "salesorder");
//query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, 1088);
}
...and here's similar code which fails in fakeXrmEasy:
void Main()
{
XrmFakedContext fakedContext = new XrmFakedContext();
IOrganizationService service = fakedContext.GetOrganizationService();
DocumentTemplate documentTemplate = new DocumentTemplate() { Id = Guid.NewGuid(), Name = "Order Summary", AssociatedEntityTypeCode = "salesorder", Status = false };
fakedContext.Initialize(new List { documentTemplate });
}
Guid GetTemplateWithEntityTypeCode(IOrganizationService service)
{
QueryExpression query = new QueryExpression("documenttemplate");
query.Criteria.AddCondition("name", ConditionOperator.Equal, "Order Summary");
//query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, "salesorder");
query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, 1088);
}
Guid GetTemplateWithEntityName(IOrganizationService service)
{
QueryExpression query = new QueryExpression("documenttemplate");
query.Criteria.AddCondition("name", ConditionOperator.Equal, "Order Summary");
query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, "salesorder");
//query.Criteria.AddCondition("associatedentitytypecode", ConditionOperator.Equal, 1088);
}
** FakeXrmEasy and Dynamics 365 / CRM version **
![image](https://user-images.githubusercontent.com/1889586/125797744-823cbe02-3764-4aea-a691-5eaab61e100e.png)
![image](https://user-images.githubusercontent.com/1889586/125797860-7d3583dd-f067-42b0-b391-b6108dd9186c.png)
Version 9 of FakeXrmEasy, v 1.57.1, Dynamics 365 online
Screenshots
If applicable, add screenshots to help explain your problem.
Working in 'real' instance
Not working in tests
Not a showstopper, but a definite difference between D365 online and FakeXrmEasy...
The text was updated successfully, but these errors were encountered: