Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll basically have to come up with a formula for determining how similar the two objects are. Pick a weight for each property and then use simple comparison to say whether that property should be counted as the same. Fuzzy matching of some type could be used, though that is going to be more complex.</p> <p>Something simple could be:</p> <pre><code>public byte Similarity(SomeType other) { byte similarity = 0; if (this.Property1 == other.Property1) similarity += 25; if (this.Property2 == other.Property2) similarity += 13; if (this.Property3 == other.Property3) similarity += 12; if (SomeFuzzyComparisonReturnsVerySimilar(this.Property4, other.Property4)) similarity += 50; return similarity; } </code></pre> <p>That is a simple method that I am defining to return a number from 0 to 100; 100 being the same and 0 being totally different.</p> <p>Once you have that, it is a fairly simple matter to select out the items that are similar enough for you to consider; eg:</p> <pre><code>var similarObjects = ListOfSomeTypes.Where(s =&gt; s.Similarity(templateObject) &gt; 75); </code></pre> <p>Or to sort them:</p> <pre><code>var sortedBySimilarity = ListOfSomeTypes.OrderByDescending(s =&gt; s.Similarity(templateObject)); </code></pre> <p>Ultimately though my point is that you have to come up with your own definition of "having the most in common with", once you have that the rest will probably be pretty easy. Not that coming up with that will necessarily be easy.</p> <p>With the additional details in your question, a possible formula would be:</p> <pre><code>public byte Similarity(A other) { byte similarity = 0; if (this.b == null | other.b == null) similarity += 25; else if (this.b == other.b) similarity += 50; if (this.c == null | other.c == null) similarity += 25; else if (this.c == other.c) similarity += 50; return similarity; } </code></pre> <p>This weights exact matches highest, null values in one object slightly less, and differences not at all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload