-3

私はlinqクエリを持っています

from elements in context.Catalog_Element
    join elementattributevalues in context.Catalog_ElementAttributeValue 
         on elements.ElementID equals elementattributevalues.ElementID
    join allowedsubcomponents in context.Catalog_AllowedSubComponents
         on new { AttributeValueID = elementattributevalues.AttributeValueID, 
                  ElementClassID = elements.ElementClassID }
         equals new { AttributeValueID = allowedsubcomponents.AttributeValueIDFilter, 
                  ElementClassID = allowedsubcomponents.ClassIDFilter }
    where allowedsubcomponents.ElementID == 
           new Guid("8c139311-f7cd-4961-a8bb-0d8dd923049e")
    select new
    {
        elements.ElementNumber,
        elements.Description
    })

これは、結合句の式の型が正しくないため、構文エラーを示しています。助けてください。

4

1 に答える 1

1

エラーメッセージは、タイプが一致しないことを明確に示しているため、タイプを確認する必要があります。

4つのフィールド(それぞれテーブルとフィールドを変更)のそれぞれに対してこれを実行して、それらのタイプが何を報告しているかを確認します。

// look at these in debugger or write them to console
var myFirstType = context.Catalog_ElementAttributeValue
    .Take(1)
    .Select (x => x.AttributeValueID)
    .GetType()
    .ToString();

var mySecondType = .....

また、データを文字列に強制して機能するかどうかを確認することで、join句をすばやく確認できます。

on new 
{ 
    AttributeValueID = elementattributevalues.AttributeValueID.ToString(),  
    ElementClassID = elements.ElementClassID.ToString() 
} 
equals new 
{   
    AttributeValueID = allowedsubcomponents.AttributeValueIDFilter.ToString(),  
    ElementClassID = allowedsubcomponents.ClassIDFilter.ToString() 
} 

次に、AttributeValueIDのみを文字列に変換して試してから、最後にElementClassIDのみを文字列に変換して試してください。失敗したものは、タイプの問題がどこにあるかを教えてくれます。

問題は実際にはnull許容型に関係しているのではないかと思います。

于 2012-06-13T23:23:27.963 に答える