
I have Workflows and Entities project withing my VS solution. Entities.cs file under Entities project is autogenerated using CrmSvcUtil.exe, containing early bounded entitiies.
I need to have BusinessUnit, Organization and etc. types in my CodeActivity workflow.For this purpose I added Entities folder under Workflows project and within it Entities.cs file has been added as a link (tried also with adding Entities dll as reference - same result) and I have the following code:
all needed using were added
using (var dataContext = new CrmDataContext(service))
{
BusinessUnit businessUnit = dataContext.BusinessUnitSet.Where(o => o.Id == businessUnitId).FirstOrDefault();
if (businessUnit != null)
{
Organization orgSetting = dataContext.OrganizationSet.Where(o => o.Id == businessUnit.OrganizationId.Id).FirstOrDefault();
if (orgSetting != null)
{
//some logic here
}
}
}
In CRM using my CodeActivity in custom workflow I have the following error:
The specified type '[MyWorkflowsNamespace.Entities.BusinessUnit' is not a known entity type.Code
I googled it and found that adding [assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute() to AssemblyInfo should help, but it didn't.
My guess is that somhow CrmDataContext is not being initialized correctly. But here my knowlege is limited and I don't know what to look for.
Have any of you experienced this issue? What could possibly cause such?
Allright, found the issue myself.
Changed
var dataContext = new CrmDataContext(service)to
CrmDataContext dataContext = new CrmDataContext(service)Helped for me, as always the issue in in details, no need to dig dipper