2016-05-20 3 views
-1

次のコードは、異なるサーバーで異なる動作をします。私はこのコード行書き込む場合は、以下の方法で:VB.NETでオブジェクトを作成すると、異なるSQLサーバー上で動作が異なる

Dim customerPositionsFromPaid = vwCustomerPositionInPaid.SelectAll().Where(conditions).Select(Function(o) New CustomerPositionFromPaidDto(o.FundingYearId.Value, o.DsoId.Value, o.CustomerId.Value, o.CustomerPosition.Value)).ToList()  

それは、一つのSQLインスタンスに結果を返すが、他のSQLインスタンスに結果を返しません。

ただし、上記の行を次のように置き換えた場合、結果は両方のSQLインスタンスで返されます。

Dim customerPositionsFromPaid = vwCustomerPositionInPaid. 
     SelectAll(). 
     Where(conditions). 
     Select(Function(o) New CustomerPositionFromPaidDto() With {.FundingYearId = o.FundingYearId.Value, .DsoId = o.DsoId.Value, .CustomerId = o.CustomerId.Value, .CustomerPosition = o.CustomerPosition.Value}). 
     ToList() 

SQL Serverインスタンスの設定が異なるか、コード自体と関係がありますか?私は、次のコードを書くことによって上記を解決するために管理するすべての

Public Shared Function [SelectAll](ByVal conditions As Expression(Of Func(Of T, Boolean))) As IEnumerable(Of T) 
    Return [SelectAll]().Where(conditions) 
End Function 

Public Shared Function [SelectAll]() As IQueryable(Of T) 
    Return Table 
End Function 

Private Shared ReadOnly Property Table() As Table(Of T) 
    Get 
     Return Context.GetTable(Of T)() 
    End Get 
End Property 
+0

あなたが正しい順序でCustomerPositionFromPaidDTo' 'へご引数の順序を持​​っていますか? 2番目の例では、プロパティを明示的に設定していますが、最初は適切な順序でプロパティを取得しています。 – ChrisF

+0

はい私はしています。 – Baahubali

答えて

-1

を選びなさい -

--function

Private Shared Function GetCustomerPositionsFromPaid(ByVal customerID As Integer, ByVal fundingYearID As Integer) As IEnumerable(Of CustomerPositionFromPaidDto) 
    Dim conditions = PredicateBuilder.True(Of vwCustomerPositionInPaid)() 
    conditions = conditions.And(Function(o) o.CustomerId.Equals(customerID)) 
    conditions = conditions.And(Function(o) o.FundingYearId.Equals(fundingYearID)) 
    conditions = conditions.And(Function(o) o.DsoId.HasValue) 

    'Dim customerPositionsFromPaid = vwCustomerPositionInPaid.SelectAll().Where(conditions).Select(Function(o) New CustomerPositionFromPaidDto(o.FundingYearId.Value, o.DsoId.Value, o.CustomerId.Value, o.CustomerPosition.Value)).ToList() 
    'Dim customerPositionsFromPaid = vwCustomerPositionInPaid.SelectAll().Where(conditions).Select(Function(o) New With {.FundingYearId = o.FundingYearId.Value, .DsoId = o.DsoId.Value, .CustomerId = o.CustomerId.Value, .CustomerPosition = o.CustomerPosition.Value}).ToList().Select(Function(o) New CustomerPositionFromPaidDto(o.FundingYearId, o.DsoId, o.CustomerId, o.CustomerPosition)).ToList() 
    Dim customerPositionsFromPaid = vwCustomerPositionInPaid. 
     SelectAll(). 
     Where(conditions). 
     Select(Function(o) New CustomerPositionFromPaidDto() With {.FundingYearId = o.FundingYearId.Value, .DsoId = o.DsoId.Value, .CustomerId = o.CustomerId.Value, .CustomerPosition = o.CustomerPosition.Value}). 
     ToList() 
    Return customerPositionsFromPaid 
End Function 

。なぜなら、前のコードが1つのサーバー上で動作し、他のサーバーでは動作しない理由はまだ分かっていないからです。

Private Shared Function GetCustomerPositionsFromPaid(ByVal customerID As Integer, ByVal fundingYearID As Integer) As IEnumerable(Of CustomerPositionFromPaidDto) 
Dim conditions = PredicateBuilder.True(Of vwCustomerPositionInPaid)() 
conditions = conditions.And(Function(o) o.CustomerId.Equals(customerID.Value)) 
conditions = conditions.And(Function(o) o.FundingYearId.Equals(fundingYearID.Value)) 
conditions = conditions.And(Function(o) o.DsoId.HasValue) 


Dim customerPositionsFromPaid = vwCustomerPositionInPaid. 
    SelectAll(). 
    Where(conditions). 
    Select(Function(o) New CustomerPositionFromPaidDto() With {.FundingYearId = o.FundingYearId.Value, .DsoId = o.DsoId.Value, .CustomerId = o.CustomerId.Value, .CustomerPosition = o.CustomerPosition.Value}). 
    ToList() 
Return customerPositionsFromPaid 

エンド機能

関連する問題