Leer desde CellSet usando LINQ

AdomdCommand cmd = new AdomdCommand(commandText, conn);
CellSet cs = cmd.ExecuteCellSet();

var result = from a in cs
             select new
             {...};

Is it possible to use LINQ to read from CellSet? I have tried using DataTable instead of CellSet but it's much slower (Example: I took a query that using DataTable takes ~45 sec to execute, but using CellSet it takes ~5 sec).

The error I get when trying to use LINQ:

Could not find an implementation of the query pattern for source type 'Microsoft.AnalysisServices.AdomdClient.CellSet'. 'Select' not found.

ACTUALIZACIÓN:

I have tried Enrico's suggestion and so far it doesn't return any errors. Next problem is how to read a value from a cell. Here's what I have tried so far:

var result = from cell in cs.Cells.Cast<Cell>()
     select new searchResultsPolicy
     {
         PolicyNumber = ...
         InsuredName = cell.Field<string>("[Insured].[DBA Name].[DBA Name].[MEMBER_CAPTION]"),
         Agency = cell.Field<string>("[Agency].[Agency Name].[Agency Name].[MEMBER_CAPTION]"),
         Market = cell.Field<string>("[Market].[Market Name].[Market Name].[MEMBER_CAPTION]"),             
         Revenue = String.Format("{0:#,##0}", cell.Field<double?>("[Measures].[Revenue]") ?? 0),
         Premium = String.Format("{0:#,##0}", cell.Field<double?>("[Measures].[Premium]") ?? 0)
     };

preguntado el 31 de enero de 12 a las 08:01

1 Respuestas

The reason you get that error is that the CellSet class in itself doesn't implement IEnumerable, which is required by LINQ.

Try executing the LINQ query over the CellSet.Cells property instead. That will return a CellCollection objeto, que implementa IEnumerable. From there you can easily convert it to an IEnumerable mediante el uso de la Enumerable.Cast<T> método.

AdomdCommand cmd = new AdomdCommand(commandText, conn);
CellSet cs = cmd.ExecuteCellSet();

var result = from cell in cs.Cells.Cast<Cell>()
             select new
             { ... };

Ver también:

Respondido el 31 de enero de 12 a las 13:01

So far it doesn't return an error. Could you please give me a hint how to read a column value from cell in select new...? I have updated my question. Thanks a lot! - ilija veselica

@ile What types are the mngmOff y fn variables? - Enrico Campidoglio

Sorry, I forgot to change the name of that variable. Instead of mngmOff it was suppose to be cell. I have fixed that now. And you can ignore fn too, it was just a name of a function that was used to format string. - ilija veselica

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.