TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
rajesh yadav
1.7k
82
9.9k
following is my api , is enumerable i s better than list etc
Feb 27 2020 11:07 PM
public
class
SCurve
{
public
DateTime ProgressDate {
get
;
set
; }
public
decimal
PlannedProgressPercentageWithWeightage {
get
;
set
; }
public
decimal
ActualProgressPercentage {
get
;
set
; }
public
decimal
PlannedPrgressPercentageWithWeightageCumulative {
get
;
set
; }
public
decimal
ActualProgressPercentageCumulative {
get
;
set
; }
}
following is what i get from database. in tuples/record.
{
"nodeHierarchy"
: [{
"L1"
:
"Mechanical"
}, {
"L2"
:
"nical"
}, {
"L3"
:
"nical2"
}],
"weightage"
:
"34"
,
"dateFrom"
:
"01 jan 2020"
,
"dateTo"
:
"04 Feb 2020"
,
"WSID"
:
"Rky6"
,
"scope"
:
"4234"
,
"IsLeafNode"
:
true
,
"Parentnode"
: [{
"L1"
:
"Mechanical"
}, {
"L2"
:
"nical"
}] }
{
"nodeHierarchy"
: [{
"L1"
:
"Mechanical"
}, {
"L2"
:
"nical"
}],
"weightage"
:
"34"
,
"dateFrom"
:
"01 jan 2020"
,
"dateTo"
:
"04 Feb 2020"
,
"WSID"
:
"Rky6"
,
"scope"
:
"4234"
,
"IsLeafNode"
:
true
,
"Parentnode"
: [{
"L1"
:
"Mechanical"
}] }
{
"nodeHierarchy"
: [{
"L1"
:
"Mechanical"
],
"weightage"
:
"34"
,
"dateFrom"
:
"01 jan 2020"
,
"dateTo"
:
"04 Feb 2020"
,
"WSID"
:
"Rky6"
,
"scope"
:
"4234"
,
"IsLeafNode"
:
true
,
"Parentnode"
: [] }
[HttpGet]
public
IEnumerable GetSCurvePlan(
string
WSId,
string
dtFrom,
string
dtTo,
string
ReportType)
{
//I get json from databse given above then transfrom it in following list.
List lstSCurveObj =
new
List();
IEnumerable IenumObject = lstSCurveObj.GroupBy(val => val.ProgressDate.AddDays(((CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek) - val.ProgressDate.DayOfWeek) + 6))
.Select(grouped =>
new
{
ProgressDate = grouped.Key,
PlannedProgressPercentageWithWeightage = grouped.Sum(Pp => Pp.PlannedProgressPercentageWithWeightage),
ActualProgressPercentage = grouped.Sum(Ap => Ap.ActualProgressPercentage),
grouped.OrderByDescending(Pc => Pc.ProgressDate).First().PlannedPrgressPercentageWithWeightageCumulative,
grouped.OrderByDescending(Ac => Ac.ProgressDate).First().ActualProgressPercentageCumulative
}).OrderBy(o=> o.ProgressDate).ToList();
return
IenumObject;
}
Q1) I have to return the data of the class in json format, so u can change anything if u want. my objective is that it should be optimised?
q2) is tolist() function is required, because, without it, it works? for optimisation.
as there is no where clause and it is used only once.
Q3) initially I was returning List but it was showing IEnumerable anonymous type cant be cast to List
so i converted it to ienumerbal how far it is good or there is other better ways?
Q4) as i have used orderby and tolist , then i have returened , will it keep the order or i have to write like following
return IenumObject.OrderBy(o => o.ProgressDate)
yours sincerely
Reply
Answers (
3
)
HttpContext.GetOwinContext() does not contain definition for
Create object URL for the FileContent in MVC Core 3.0