Friday 15 July 2011

.net - Linq query no longer ordered properly after .Distinct() used -


Below is a simple LINQ query in a jQuery autocomplete list I'm using to fill Am i The list is ordered properly until that . Undoubtedly () The method is called whether there is a way to remove a duplicate from a list and can give me an indication to keep it in order?

  public JsonResult OverrideSearch (string duration) {var in DRM db.ZipCodeTerritory d where d.DrmTerrDesc.Contains (word) orderby d.DrmTerrDesc selection = d.DrmTerrDesc =; Drm = drm.Distinct (); Return JSON (Drum, Jansenview's Behavior, Elove Gate); }  "itemprop =" text "> 

after the

 < Code> Public JsonResult OverrideSearch (string duration) {var DRM = db.ZipCodeTerritory. Where (d = & gt; d.DrmTerrDesc.Contains (word)). Select (d = & gt; d.DrmTerrDesc) .Distinct () OrderBy (d = & gt; d); Return JSON (Drum, Jansenview's Behavior, Elove Gate); }   

or query syntax (I do not like to mix query and method syntax):

  public JsonResult OverrideSearch (string term) {var DRM = DB to DB Zipcode template where d.DrmTerrDesc.Contains (word) select d.DrmTerrDesc; Drm = drm.Distinct (); Return Jason (DOM order B (D => D), Jason Yewest Beaver. Elove Gate); }   

BTW There is a comment on the method on MSDN which states that this is usually the sequence return sequence:

query behavior is that As a result of the execution occurs, an expression tree which represents different calling (IQueryable) depends on the implementation of the source parameter type. The expected behavior is that it gives an antordial sequence of unique items in the source.

No comments:

Post a Comment