0

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();
4

1 回答 1

1

这个答案只是扩展了 Nicknow 和我自己的评论,因此可以将问题标记为已回答。

Dynamics CRM Linq Provider 要求范围变量是 where 子句中的左侧术语。

您的 where 子句应该是:

where (Guid)SI["sdkmessageprocessingstepid"] == (Guid)S["sdkmessageprocessingstepid"]

代替:

where (Guid)S["sdkmessageprocessingstepid"] == (Guid)SI["sdkmessageprocessingstepid"]
于 2014-02-10T15:38:37.320 回答