c # linq devuelve una matriz multidimensional desde linq
Quiero devolver una matriz multidimensional para mantener en una sesión pero no estoy seguro de cómo devolverla desde linq:
public string[] GetCountryAndManufacturerForUser(int userId)
{
var array = (from xx in _er.UserRoles
join xy in _er.Countries on xx.CountryId equals xy.Id
join xz in _er.Manufacturers on xx.ManufacturerId equals xz.Id
where xx.UserId == userId
select new { xy.Name, xz.Description }).ToArray();
return??
}
Sé que estoy haciendo algo mal aquí, simplemente no estoy seguro de qué.
Editar:
Los siguientes campos deben devolverse: xy.Name, xz.Description
me gusta:
{ "1", "aaa" },
{ "2", "bbb" }
Editar:
He intentado el siguiente ejemplo y aún no han llegado a donde necesito estar. Pensé que algo como lo siguiente debería funcionar:
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public string[,] GetCountryAndManufacturerForUser(int userId)
{
var array = (from xx in _er.UserRoles
join xy in _er.Countries on xx.CountryId equals xy.Id
join xz in _er.Manufacturers on xx.ManufacturerId equals xz.Id
where xx.UserId == userId
select new { xy.Name, xz.Description }).ToArray();
return array;
}
Pero se queja de la matriz de retorno;
Editar:
Lo más cercano que tengo es el siguiente:
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public string[][] GetCountryAndManufacturerForUser(int userId)
{
//var array = (from xx in _er.UserRoles
// join xy in _er.Countries on xx.CountryId equals xy.Id
// join xz in _er.Manufacturers on xx.ManufacturerId equals xz.Id
// where xx.UserId == userId
// select new { xy.Name, xz.Description }).ToArray();
var countryArray = (from xx in _er.UserRoles
join xy in _er.Countries on xx.CountryId equals xy.Id
join xz in _er.Manufacturers on xx.ManufacturerId equals xz.Id
where xx.UserId == userId
select xy.Name).ToArray();
var manufacturerArray = (from xx in _er.UserRoles
join xy in _er.Countries on xx.CountryId equals xy.Id
join xz in _er.Manufacturers on xx.ManufacturerId equals xz.Id
where xx.UserId == userId
select xz.Description).ToArray();
// return array;
return new string[][] { countryArray, manufacturerArray };
}
pero esto devuelve dos matrices:
var userManuCountry = _userRoleRepository.GetCountryAndManufacturerForUser(u.Id);
userManuCountry {string[2][]} string[][]
[0] {string[6]} string[]
[0] "Germany" string
[1] "France" string
[2] "United Kingdom" string
[3] "Netherlands" string
[4] "United States" string
[5] "United Kingdom" string
- [1] {string[6]} string[]
[0] "Dove" string
[1] "Dove" string
[2] "Dove" string
[3] "Dove" string
[4] "Dove" string
[5] "Sure" string