Entity Framework Include OrderBy random generates duplicate data

后端 未结 6 602
[愿得一人]
[愿得一人] 2020-11-30 02:29

When I retrieve a list of items from a database including some children (via .Include), and order the randomly, EF gives me an unexpected result.. I creates/clones addition

6条回答
  •  情歌与酒
    2020-11-30 02:36

    From theory: To sort a list of items, the compare function should be stable relative to items; this means that for any 2 items x, y the result of x< y should be the same as many time is queried(called).

    I think the issue is related to misunderstanding of specification(documentation) of OrderBy method: keySelector - A function to extract a key from an element.

    EF didn't mention explicitly if the provided function should return the same value for same object as many times is called (in your case returns different/random values), but I think the "key" term that they used in documentation implicitly suggested this.

提交回复
热议问题