Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
How can a linq query be converted to JavaScript array containing only values?

I have a JavaScript grid library (it creates a table on the page) that accepts a JavaScript array as input, for rendering in the grid. I'm not certain, however, how to convert a Linq-to-SQL query (against a SQL Server database) to a JavaScript array containing only values.

I tried this, but it included the table column names in the JSON key (and I don't want JSON anyway, I want a JavaScript string array, unless this can be converted to an array?):

JsonConvert.SerializeObject(query)

Example of the format I need to produce:

[1,2,3],[4,5,6]

Environment: .NET Core 3.1

edit: Here is a sample of what I've currently got, this returns the less than desirable JSON (due to the query results being so large, having a JSON key for very element is going to literally double the size of the query):

Devices Table

ID   Name
1    iPhone7
2    iPhone8
3    iPhone9

Needed Array (Note: no column names)

[1, "iPhone7"],[2, "iPhone8"],[3, "iPhone9"]

Current C# code in the controller method (returns undesirable key for every element currently)

var query = db.Devices;
var formattedResult = JsonConvert.SerializeObject(query);
return Ok(formattedResult);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Technically, you could do this:

var query = db.Devices.AsEnumerable()
    .Select(d => new object[]{d.ID, d.Name});
var formattedResult = JsonConvert.SerializeObject(query);
return Ok(formattedResult);

But then the code on the other end of your request is going to have to translate all those arrays back into objects.

It's rarely worthwhile to complicate your model like this in order to optimize the size of your network traffic. If you're pulling enough items over the wire to make this a performance issue, you're likely to encounter a variety of other performance issues. I would first consider other options, like implementing paging.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Did you try

var query = db.Devices.ToList(); 
var array = JArray.FromObject(query);
return Ok(formattedResult)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda