Click here to Skip to main content
14,937,574 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the code is given below
var IS = (from c in xfeed.ciqCompanies
      join s in xfeed.ciqSecurities on c.companyId equals s.companyId
      join ti in xfeed.ciqTradingItems on s.securityId equals ti.securityId
      join e in xfeed.ciqExchanges on ti.exchangeId equals e.exchangeId
      join fp in xfeed.ciqLatestInstanceFinPeriods on c.companyId equals fp.companyId
      join pt in xfeed.ciqPeriodTypes on fp.periodTypeId equals pt.periodTypeId
      join fd in xfeed.ciqFinancialDatas on fp.financialPeriodId equals fd.financialPeriodId
      join di in xfeed.ciqDataItems on fd.dataItemId equals di.dataItemId
      where fd.dataItemId == 3069
      && fp.periodTypeId ==1
      && fp.fiscalYear>=DateTime.Now.AddYears(-5).Year && fp.fiscalYear<=DateTime.Now.Year
      && ti.tickerSymbol == tickerSymbol
      && e.exchangeSymbol == exchangeSymbol
      select new
Updated 14-May-20 23:58pm

Don't pass any anonymous type to the view. Rather create one ViewModel of your models & make a query for it.

Read this for example:[^][^]

Create a concrete class (MyViewModel or whatever) that has properties for your fields, so CompanyName, CompanyID, TickerSymbol etc, and create a List<myviewmodel> from your query rather than the anonymous type you're creating now.

select new MyViewModel
          CompanyName = c.companyName,
          CompanyID = c.companyId,

Have your view accept List<MyViewModel> as it's type. Not sure if the above code is the exact syntax you need, google for converting linq query to concrete class if it isn't.
First, you create a concrete class "InfoViewModel" for example that has properties for your fields in the select statement: CompanyName, CompanyID, TickerSymbol, etc,

public class InfoViewModel<br />
    {<br />
        public string CompanyName { get; set; }<br />
        public string CompanyID { get; set; }<br />
        etc...<br />

then create a List<infoviewmodel> from your query in the PageModel
public List<InfoViewModel> Info= new List<InfoViewModel>();
and then create a foreach loop after the select statement to store the query result in the list you created, in order not to have a conflict regarding the anonymous type error that you will face.
<br />
select new <br />
      {<br />
          CompanyName = c.companyName,<br />
          CompanyID = c.companyId,<br />
          etc...<br />
      }).ToList();<br />
<br />
<br />
 foreach (var item in q)<br />
                {<br />
                    InfoViewModel info = new InfoViewModel();<br />
                    info.CompanyName = item.CompanyName ;<br />
                    info.CompanyID = item.CompanyID ;<br />
                    etc...<br />
                    Info.Add(info);<br />
                }<br />

then in the .cshtml ViewModel:
<tbody><br />
                @foreach (var item in Model.Info)<br />
                {<br />
                    <tr><br />
                        <td><br />
                            @Html.DisplayFor(modelItem => item.CompanyName)<br />
                        </td><br />
                        <td><br />
                            @Html.DisplayFor(modelItem => item.CompanyID)<br />
                        </td><br />
                    </tr><br />
                }<br />
Richard Deeming 15-May-20 10:09am
This was already suggested in solutions 1 and 2, which were posted five years ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900