2016-05-20 6 views
-1

Ich habe folgenden Code, der auf verschiedenen Servern unterschiedlich verhält. Im folgenden Verfahren, wenn ich schreibe diese Codezeile:Erstellen eines Objekts in VB.NET verhält sich auf verschiedenen SQL-Servern unterschiedlich

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

es Ergebnis auf einer SQL-Instanz zurückgibt, aber nicht wieder auf andere SQL-Instanz führen.

Wenn ich jedoch die obige Zeile durch die folgenden ersetzen, gibt es Ergebnis für beide SQL-Instanzen.

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

Könnte es sein, weil sql Server Instanzen unterschiedliche Einstellungen haben oder es etwas mit dem Code selbst zu tun hat?

--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 

--Select Alle

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

Haben Sie die Reihenfolge der Argumente 'CustomerPositionFromPaidDTo' in der richtigen Reihenfolge? Im zweiten Beispiel legen Sie die Eigenschaften explizit fest, aber im ersten Fall verlassen Sie sich darauf, sie in die richtige Reihenfolge zu bringen. – ChrisF

+0

Ja ich habe bitte. – Baahubali

Antwort

-1

Ich schaffe das oben zu lösen, indem Sie den folgenden Code zu schreiben. Da clientid und financingyearid nullbare Objekte sind, musste ich das .Value-Attribut verwenden, bin mir aber immer noch nicht sicher, warum der vorherige Code auf einem Server funktioniert und nicht auf dem anderen.

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 

End Function