Click here to Skip to main content
       

LINQ

 
GeneralRe: Error : Calling SSIS package from .Net PinmemberVuyiswa Maseko9-Nov-09 21:45 
GeneralRe: Error : Calling SSIS package from .Net Pinmemberkumarkjai9-Nov-09 21:55 
GeneralRe: Error : Calling SSIS package from .Net PinmemberVuyiswa Maseko9-Nov-09 22:32 
GeneralRe: Error : Calling SSIS package from .Net Pinmemberkumarkjai10-Nov-09 22:54 
GeneralRe: Error : Calling SSIS package from .Net PinmemberVuyiswa Maseko10-Nov-09 22:58 
QuestionLinq2Sql: Adding an object with childs PinmemberQuake2Player24-Oct-09 14:00 
QuestionHow do I do an effective Except PinmemberTheFoZ22-Oct-09 5:55 
AnswerRe: How do I do an effective Except PinmemberGideon Engelberth22-Oct-09 8:27 
Perhaps the difference comes from the different conditions you are using. In the original, you are not taking "distinct" items only and you are comparing based on both processId and process. In the LINQ version, you are taking both distinct and comparing only on processID.
 
There is an overload of Except that may help you out here. It takes an additional IEqualityComparer parameter. You can use that parameter to implement the custom equality operation. Also, Except has an implementation detail that trips up everyone the first time they use except. As well as being "Equals", the objects must have the same "GetHashCode" because Except will use a HashSet to store the objects from the first sequence. This also has the side effect of automatically doing a "distinct" on the two sequences. One trick you can use to get around this is to override GetHashCode on your object to just return a constant value that is the same for all instances. The tradeoff is that hashtables and hashsets will go from O(1) to O(n).
 
Below is a simple IEqualityComparer I whipped up to take a delegate for the comparisons so you don't have to make a separate class for each comparison. (If there is something similar in the framework, I don't know about it.)
 
Public Class DelegateEqualityComparer(Of T)
    Implements IEqualityComparer(Of T)
 
    Public Sub New(ByVal comparison As Func(Of T, T, Boolean))
        Me.New(comparison, Nothing)
    End Sub
    Public Sub New(ByVal comparison As Func(Of T, T, Boolean), ByVal hash As Func(Of T, Integer))
        If comparison Is Nothing Then Throw New ArgumentNullException("comparison")
        _comparison = comparison
        _hash = hash
    End Sub
 
    Private _comparison As Func(Of T, T, Boolean)
    Private _hash As Func(Of T, Integer)
 
    Public Function ComparerEquals(ByVal x As T, ByVal y As T) As Boolean Implements System.Collections.Generic.IEqualityComparer(Of T).Equals
        Return _comparison(x, y)
    End Function
 
    Public Function ComparerGetHashCode(ByVal obj As T) As Integer Implements System.Collections.Generic.IEqualityComparer(Of T).GetHashCode
        If _hash Is Nothing Then
            Return obj.GetHashCode()
        Else
            Return _hash(obj)
        End If
    End Function
 
End Class

GeneralRe: How do I do an effective Except PinmemberTheFoZ22-Oct-09 21:56 
GeneralDynamic Aggregates on Report Rows PinmemberBrady Kelly21-Oct-09 10:05 
GeneralRe: Dynamic Aggregates on Report Rows PinmvpJ4amieC21-Oct-09 21:57 
GeneralRe: Dynamic Aggregates on Report Rows PinmemberBrady Kelly22-Oct-09 0:57 
GeneralRe: Dynamic Aggregates on Report Rows PinmvpJ4amieC22-Oct-09 1:24 
GeneralRe: Dynamic Aggregates on Report Rows PinmemberBrady Kelly22-Oct-09 5:14 
GeneralRe: Dynamic Aggregates on Report Rows PinmvpJ4amieC22-Oct-09 5:34 
GeneralRe: Dynamic Aggregates on Report Rows PinmemberBrady Kelly22-Oct-09 8:23 
GeneralRe: Dynamic Aggregates on Report Rows PinmvpJ4amieC22-Oct-09 22:03 
GeneralRe: Dynamic Aggregates on Report Rows PinmemberBrady Kelly23-Oct-09 20:54 
GeneralRe: Dynamic Aggregates on Report Rows PinmemberGideon Engelberth22-Oct-09 6:01 
GeneralRe: Dynamic Aggregates on Report Rows PinmemberBrady Kelly22-Oct-09 8:24 
QuestionInsert New Row in XML? PinmemberAman Bhullar20-Oct-09 19:10 
AnswerRe: Insert New Row in XML? PinmemberMirko198021-Oct-09 5:32 
QuestionHow to use DbLinq that suport Linq To Oracle? Pinmembermehdi talebi20-Oct-09 8:44 
AnswerRe: How to use DbLinq that suport Linq To Oracle? Pinmemberspiritboy15-Dec-09 18:27 
QuestionLINQ-GRIDVIEW Pinmembersris 42620-Oct-09 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 22 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid