Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error received "No best type found for implicitly-typed array"

Tags:

json

c#

implicit

This is my code for creating Json response for jqGrid and for new keyword for defining cell member I receive following message "No best type found for implicitly-typed array".

var resRows = results.Select(record => 
            new 
            {
                id = record.Reference,
                cell = **new** []
                {
                    record.Reference,
                    record.TradeDate.ToShortDateString(),
                    record.Currency1,
                    record.Currency2,
                    record.Notional.ToString(),
                    record.EffectiveDate.ToShortDateString(),
                    record.Quote.ToString()                        
                }
            }).ToArray();

What am I doing wrong here?

like image 944
Draško Avatar asked Jun 28 '12 12:06

Draško


2 Answers

Assuming Reference, Currency1 and Currency2 are strings, just declare it as a string array:

var resRows = results.Select(record => 

    new 
    {
        id = record.Reference,
        cell = new string []
        {
            record.Reference,
            record.TradeDate.ToShortDateString(),
            record.Currency1,
            record.Currency2,
            record.Notional.ToString(),
            record.EffectiveDate.ToShortDateString(),
            record.Quote.ToString()                        
        }
    }).ToArray();
like image 101
D Stanley Avatar answered Sep 20 '22 03:09

D Stanley


If you prepare data for jqGrid (like in your code), you can define your own jsonReader and just skip the cell array (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data):

jsonReader: {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false,
        userdata: "userdata"
    },

Then something like:

var result = new
{
    total = (int)count / grid.PageSize),
    page = grid.PageIndex,
    records = count,
    rows = results.Select(record => 
                    select new
                    {
                        Reference = record.Reference,
                        TradeDate = record.TradeDate,
                        ..
                     }).ToArray()
}
like image 33
Gerard Avatar answered Sep 21 '22 03:09

Gerard