Compare primary keys instead of object reference

2 posts, 0 answers
  1. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 25 Apr 2013 Link to this post

    Hello.

    The code below always returns false. I guess "Contains" doesn't compare primary keys to check equality.
    Successors is a self-referencing  n:m relation.

    Is there an option to switch this behaviour or a recommended way to handle things like this?

    King regards
    Bernd
    idee5.DispatcherModel.Action enteredAction = context.Actions.Single(a => a.Id == TransactionInput.Text);
    if (lastTransaction.Action.Successors.Contains(enteredAction))
  2. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 29 Apr 2013 Link to this post

    Solved it myself by using the Any-Function.

    if (lastTransaction.Action.Successors.Any(a => a.Id.ToString() == TransactionInput.Text))
  3. DevCraft banner
Back to Top