Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

should we put order by in list of objects while returning form api or they keep the order in which they are created.

$
0
0

public class pdate
{

public DateTime ProgressDate { get; set; }

public prog decimal{get;set;]

}

List<pdate> listpdate = new List<pdate>();
SCurve scurveObj = null;

DateTime dtFrom1 = DateTime.SpecifyKind(Convert.ToDateTime("01 jan 2019").Date, DateTimeKind.Utc);
DateTime dtTo1 = DateTime.SpecifyKind(Convert.ToDateTime("01 feb 2019").Date, DateTimeKind.Utc);

for (DateTime i = dtFrom1; i <= dtTo1; i = i.AddDays(1))
{
pdate = new pdate();

pdate.ProgressDate = i.Date;

pdate.prog = 10;

listpdate.Add(pdate);

}

this code is in api which returns listpdate;

Q1) in return stmt should i put order by or will it keep the order in which i have inserted the objects, and finally the api is called in .js so will get every thing in the same order

in which i have entered.

return listpdate.OrderBy(o => o.ProgressDate).ToList();

q2) if i group by on one col in return stmt , then should we use order by or it will keep the objects in listpdate ordered by progressdate in the order i have entered in loop.

so in simple should i put ordeby or not in this case. where i need the data at .js on page order by progress date.

<div> return listpdate.GroupBy(val => DateTime.SpecifyKind(new DateTime(val.ProgressDate.Year, val.ProgressDate.Month,</div> <div>                                                     DateTime.DaysInMonth(val.ProgressDate.Year, val.ProgressDate.Month)),DateTimeKind.Utc))</div><div>                    .Select(grouped => new pdate()</div> <div>                    {</div> <div>                        ProgressDate = grouped.Key</div> <div>                       ,</div> <div>                       prog = grouped.Sum(Pp => Pp.prog)</div> <div>                       }).OrderBy(o => o.ProgressDate).ToList();</div> <div> </div>

Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>