This is a migrated thread and some comments may be shown as answers.

Compare primary keys instead of object reference

1 Answer 46 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bernd
Top achievements
Rank 2
Bernd asked on 25 Apr 2013, 10:20 AM
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))

1 Answer, 1 is accepted

Sort by
0
Bernd
Top achievements
Rank 2
answered on 29 Apr 2013, 08:57 AM
Solved it myself by using the Any-Function.

if (lastTransaction.Action.Successors.Any(a => a.Id.ToString() == TransactionInput.Text))
Tags
Data Access Free Edition
Asked by
Bernd
Top achievements
Rank 2
Answers by
Bernd
Top achievements
Rank 2
Share this question
or