I have a one dimensional string[] array as follows
string[] header = new string[30];
public class GetList
{
public string ServerID;
public string Name;
public GetList(string sName, string cName)
{
this.ServerID = sName;
this.Name = cName;
}
}
and I have a query which will return the list of server names and component names as follows
var query = (from a in this.hmdb.Servers
join b in this.hmdb.Components
on a.ServerID equals b.ServerID
select new { a.ServerID, b.Name});
how to insert the query result into the string[] header ?
EDIT
when i tried something like this
var query = (from a in this.hmdb.Servers
where a.ServerID.Contains(match)
join b in this.hmdb.Components
on a.ServerID equals b.ServerID
select new
{
ID = a.ServerID,
Name = b.Name
}).ToArray();
I get the result as list of ServerID and Names
UPDATE
here is the explanation for the marked answer..
what's happening is that it will create a queryable/list of ServerID and Name then convert it to Enumerable and create a List of string using the .Select() extension and convert it to array of string select new { a.ServerID, b.Name } --> creates a list/iqueryable of anonymous type that has ServerID and Name properties..
AsEnumerable() --> convert it to Enumerable so we can use string.Format because SQL to LINQ doesn't support string.Format
Select(x => string.Format("{0} - {1}", x.ServerID, x.Name)) --> do a Select in order to create a list of String using the ServerID and Name
ToArray() --> simply convert it to a String[] there.
string, but you deal with aGetListclass. Doesn't match. Provide a way to convert aGetListobject to string, or use an array ofGetListobjects.