c# - LINQ Error: Method not recognized -
I am using the following code which is compiled without problems, but when I call the method, This error is found:
Units do not recognize the 'System.String ToString ()' method to the LINQ units, and this method can not be translated into a store expression.
public IEnumerable & LT; String & gt; GetAllCitiesOfCountry (int id) {var ad = from one of the institutions. Adwords where a.CountryID == ID select one. City.Distinct () ToString (); Var fa = entities.FacilityAddresses where b.CountryID == ID select b.City.Distinct (). ToString (); Return advertisement Conakat (FA). Distinction (); }
Can it be rewritten to work?
How is the
city ? If it is already a string, just drop it
. Undoubtedly (). ToString () Call If this is a complex type, then select the name of the city by type.
Update : Depending on your comment, you should leave the Distint () and ToString () calls. The last union on the collection of city names should give you a unique city name.
Public IEnumerable & lt; String & gt; GetAllCitiesOfCountry (int id) {var ad = from one in institutions Apparel where a.CountryID == ID select a.City; Var fa = entities.FacilityAddresses where b.CountryID == ID selection of b.City; Return advertisement Union (fa); }
Comments
Post a Comment