English 中文(简体)
Linq ToSql——奇怪行为的比喻
原标题:LinqToSql - Bit of a strange behavior

我试图执行以下法典。 但是,这部法典打破了。

    Dim complaints = From comp In Me.Db.Complaints _
    Let varX = GetVariations().WithVariationId(If(comp.ItemPropertyXVariationId, 0)) _
    Let varY = GetVariations().WithVariationId(If(comp.ItemPropertyYVariationId, 0)) _
    Select New Hogia.Retail.POS.Data.Complaint() With _
    {.ItemXVariation = If(varX Is Nothing, DirectCast(String.Empty, String), varX.Name)}

。 项目十五 现在,我以以下方式在准则说明之外测试了该法典的行文,并且进行了罚款,并按预期结果恢复了适当结果。

    Dim varXX = GetVariations().WithVariationId(0)
    Dim varYY = GetVariations().WithVariationId(0)
    Dim temp As New Complaint() With {.ItemXVariation = If(varXX Is Nothing, DirectCast(String.Empty, String), varXX.Name)}

请允许我帮助我理解一下,为什么在第一个部分,该守则会中断。 这里的错误。

这里要传达的信息(帮助我说出这一点)

Could not translate expression Table(Complaint).Select(comp => new VB$AnonymousType_22 (comp = comp, varX = Invoke(value(System.Func1[System.Linq.IQueryable1[ Data.ItemPropertyVariation]])).WithVariationId((comp.ItemPropertyXVariationId ?? 0)))).Select($VB$It1 => new VB$AnonymousType_32($VB$It1 = $VB$It1, varY = Invoke(value(System.Func1[System.Linq.IQueryable1[Data.ItemPropertyVariation]])).WithVariationId(($VB$It1.comp.ItemPropertyYVariationId ?? 0)))). Select($VB$It => new Complaint() {ItemXVariation = IIF((Convert($VB$It.$VB$It1.varX) = null), null, $VB$It.$VB$It1.varX.Name)}) into SQL and could not treat it as a local expression.

问题回答

Is GetVariations () a means of You. lin子将试图把它称作一种储存程序。

你们要么需要写一个储存的程序,要么获得完整的实体,然后用你的“完整”声明使用linq(物体)。 这将称为“你”

这引起了一种常见的误解,即你能够利用任何东西来对付可贵的教条,而且它只是得到魔法的翻译。 情况并非如此。

问题在于,你使用班克2SQL Linq供应商不支持的代码。

简言之,Linq通过将你询问中定义的表达树解释为目标语言(如Linq2Sql、T-SQL)。 它不能简单地将任何方法翻译成适当的q......

因此,在使用linq2sql(或为此提供的任何其他班子)时,你应当知道哪些电梯操作商得到了支持,以及如何支持。

关于向Sql翻译的更深入的解释,





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签