2016-07-30 8 views
0

要件:のLINQとEFで結合テーブル上の条件節を作成します

はこの時点で注文の現在のステータスを表示します。これにより、まだ出荷されていないすべての注文と、今日出荷された注文が返されます。

データ構造:

OrderHeader (1) -> (many) ShippingContainerHeaders

以下の私のコードのコピー。もともとはoh.CreatedOnの部分で作業していましたが、これはコメントアウトされています。しかし、その要件は洗練され、その代わりに結合テーブルShippingContainerHeader.ShipDateTimeUTCの特定の出荷日を使用して出荷されたものを考慮する必要があります。その注文の船舶容器のいずれかにShipDateTimeUTCのTodayがある場合は、それを含めます。しかし、私は以下の持っているものコンパイルして、このエラー与えません。

Cannot compare elements of type 'System.Collections.Generic.ICollection`1[[OTIS.Domain.InventoryMgmt.ShippingContainerHeader, OTIS.Domain, Version=1.5.6054.27019, Culture=neutral, PublicKeyToken=null]]'. Only primitive types, enumeration types and entity types are supported. 
:私は .Where .Anyに変更すると

Error 17 Type of conditional expression cannot be determined because there is no implicit conversion between 'System.Collections.Generic.IEnumerable<OTIS.Domain.InventoryMgmt.ShippingContainerHeader>' and 'bool'

return orderHeaderRepository 
    .SearchFor(oh => 
     oh.FacilityId == intFacilityId 
     && oh.OrderType == OrderHeader.OrderTypes.ShipOrder.ToString() 
     && (
      oh.StatusId >= (int)OrderHeader.Statuses.Shipped && oh.ShippingContainerHeaders != null 
      ? oh.ShippingContainerHeaders.Where(sh => sh.ShipDateTimeUTC >= startDateTime) //(oh.CreatedOn >= startDateTime) && (oh.CreatedOn <= endDateTime) 
      : oh.Id > 0 
      ) 
     ) 

UPDATE

を、私はこのエラーを取得します

私のソリューション

私が達成しようとしていたことをする方法がないという点で受け入れられた答えは具体的ではありますが、代わりの解決法はありません。結局、最初にUNIONクエリを作成して、出荷されていないすべての注文と出荷された注文を最初に照会し、2つの照会で共用を実行しなければなりませんでした。

+0

問題が何ですか?質問はなんですか? –

+0

@IvanStoev申し訳ありませんが、正確なエラーメッセージを追加しました。それはコンパイルされません。 –

+0

'Where'を' Any'に変更する –

答えて

0
oh.ShippingContainerHeaders != null 
      ? oh.ShippingContainerHeaders.Where(sh => sh.ShipDateTimeUTC >= startDateTime) //(oh.CreatedOn >= startDateTime) && (oh.CreatedOn <= endDateTime) 
      : oh.Id > 0 

これなステートメントが正しくありません:

oh.ShippingContainerHeaders .Where(sh => sh.ShipDateTimeUTC >= startDateTime)=IEnumerable<ShippingContainerHeader>()

oh.Id > 0はブール値です!

read hereなぜ!

Type of conditional expression cannot be determined because there is no implicit conversion between 'class1' and 'class2' Conversions between classes are useful when you want objects of different classes to work with the same code. However, two classes that work together cannot have mutual and redundant conversions, or no implicit conversions. The types of class1 and class2 are determined independently, and the more general type is selected as the type of the conditional expression. For more information about how types are determined, see Conditional operator cannot cast implicitly. To resolve CS0173, verify that there is one and only one implicit conversion between class1 and class2, regardless of which direction the conversion is in and regardless of which class the conversion is in. For more information, see Implicit Numeric Conversions Table (C# Reference) and Conversion Operators (C# Programming Guide).

関連する問題