I am pulling back information about locations from a webservice. The service returns an array of WebObjectsDTOs which holds all of the objects. The objects can be of different types but in this case I'm requesting only objects of type MlaLocation. I then need to orderby the locations name. The problem I ran into was that I cannot do an orderby on searchResult.WebObjectDTOs because it's the base object and does not have access to the location name.
I thought my solution would be to cast searchResult.WebObjectDTOs to MlaLocationDTO[] since searchResult is only returning an array of MlaLocationDTO. But what I'm seeing in debug is that mlaLocations is being set as null even though searchResult.WebObjectDTOs has objects in it.
MlaWebObjectServiceClient svc = new MlaWebObjectServiceClient();
SearchRequest searchRequest = new SearchRequest(){
OperatingCompanyId = Guid.Parse("e4be5383-03d0-4a99-9613-6238dd2396ad"),
WebObjectType = "MlaLocation"
};
SearchResult searchResult = svc.GetMlaWebObjects(searchRequest);
MlaLocationDTO[] mlaLocations = searchResult.WebObjectDTOs as MlaLocationDTO[];
rptLocationsList.DataSource = mlaLocations.OrderBy(m => m.Name);
rptLocationsList.DataBind();
object[] a = new string[] { "a", "b", "c" }is legal.object[] a = new string[] { "a", "b", "c" }; string[] b = (string[])a;But this is not:object[] a = new object[] { "a", "b", "c" }; string[] b = (string[])a;