I have beaten my head on the wall trying to find out what is causing this error.
When I run my project it throws me the following error when I query against Dynamics CRM database using Linq Query.
The variable SI of type Microsoft.Xrm.Sdk.Entity is refenced on this scope, but it is not defined"
Important point: I have written a coment above the line that's causing the error
any help will be appreciated!
List<InnerAttributes> myQuery = (from PA in orgContext.CreateQuery("pluginassembly")
join PT in orgContext.CreateQuery("plugintype")
on (Guid)PA["pluginassemblyid"] equals (Guid)PT["pluginassemblyid"]
select new InnerAttributes
{
assembly = PA.Contains("name") ? PA["name"].ToString() : string.Empty,
left1 = (from S in orgContext.CreateQuery("sdkmessageprocessingstep")
where (Guid)S["plugintypeid"] == (Guid)PT["plugintypeid"]
select new Left1
{
message = S.Contains("sdkmessageid") ? S["sdkmessageid"].ToString() : string.Empty,
left2 = (from SI in orgContext.CreateQuery("sdkmessageprocessingstepimage")
//Here is the error, if I take that where clause off it runs well, however it doesn't give me expected return
where (Guid)S["sdkmessageprocessingstepid"] == (Guid)SI["sdkmessageprocessingstepid"]
select new Left2
{
imageAttributes = SI.Contains("attributes") ? SI["attributes"].ToString() : string.Empty,
}
).FirstOrDefault()
}).FirstOrDefault()
}
).ToList();