Converting ORDER BY with multiple case statements
I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?
SELECT
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc
My convertion without case statement below,
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
c# linq
add a comment |
I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?
SELECT
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc
My convertion without case statement below,
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
c# linq
Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48
add a comment |
I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?
SELECT
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc
My convertion without case statement below,
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
c# linq
I need to covert below SQL query as LINQ query. How can I put conditional if case statements within the order by clause using LINQ?
SELECT
td1.TYPEDEFDESC +':'+ td2.TypeDefDesc as ResponseTypeReason,
convert(varchar(20),td1.TypeDefid) +'~'+ convert(varchar(20),td2.TypeDefcode) as ResponseTypeCode,
td1.TYPEDEFID,
td1.TYPEDEFGROUP,
td1.TYPEDEFCODE,
td1.TYPEDEFDESC,
td1.PARENTID
FROM TYPEDEFINITION td1 WITH (NOLOCK)
join TypeDefinition td2 with (nolock)
on td1.TypeDefid = td2.ParentId
WHERE td1.TypeDefGroup='ResponseType'
and td1.Active=1
and td2.Active=1
order by
case when td1.TypeDefDesc='Successful' and td1.TypeDefGroup='ResponseType' then 1
when td1.TypeDefDesc='Failed' and td1.TypeDefGroup='ResponseType' then 2
when td1.TypeDefDesc='Failed Attempt' and td1.TypeDefGroup='ResponseType' then 3 end asc
My convertion without case statement below,
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby(t1.TypeDefGroup)
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
c# linq
c# linq
edited Nov 23 '18 at 6:14
Uwe Keim
27.4k31128210
27.4k31128210
asked Nov 23 '18 at 5:50
Sivaraj Ganesan
168
168
Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48
add a comment |
Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48
Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48
Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48
add a comment |
3 Answers
3
active
oldest
votes
Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup == strTypeDefGrp
orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
add a comment |
You should be able to do this using a Ternary Operator.
The ternary operator lets you convert a somewhat long-winded if/else
statement into a single line. For example:
int a;
if(test) {
a = 1;
} else {
a = 2;
}
Can get converted into:
int a = test ? 1 : 2;
More complicated expressions can also be made by using multiple ternary expressions.
e.g.
int a;
if(testA) {
a = 1;
} else if(testB) {
a = 2;
} else {
a = 3;
}
Can be converted into this:
int a = testA ? 1 : // if(testA)
testB ? 2 : // else if(testB)
3; // else
Alternatively formatted as:
int a = (testA ? 1 : (testB ? 2 : 3));
In your scenario, the ternary operator can be used in the orderby
clause:
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby
((t1.TypeDefDesc == "Successful" &&
t1.TypeDefGroup == "ResponseType") ? 1 :
(t1.TypeDefDesc == "Failed" &&
t1.TypeDefGroup == "ResponseType") ? 2 :
(t1.TypeDefDesc == "Failed Attempt" &&
t1.TypeDefGroup == "ResponseType") ? 3 :
4) // Whatever the "else" group is
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
Check out the MSDN docs for more info.
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
add a comment |
Done this by mywork. using ThenBy
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441251%2fconverting-order-by-with-multiple-case-statements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup == strTypeDefGrp
orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
add a comment |
Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup == strTypeDefGrp
orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
add a comment |
Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup == strTypeDefGrp
orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
Try to use trinary ifelse operator inside the orderby statement itself like this modify according to your needs
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup == strTypeDefGrp
orderby (t1.TypeDefDesc == "Successful" && td1.TypeDefGroup == "ResponseType" ? 1 : (td1.TypeDefDesc == "Failed" && td1.TypeDefGroup == "ResponseType" ? 2 : (td1.TypeDefDesc == "Failed Attempt" && td1.TypeDefGroup == "ResponseType" ? 3 : 4)))
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
answered Nov 23 '18 at 6:35
irfandar
1,0321016
1,0321016
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
add a comment |
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
Thanks @irfandar
– Sivaraj Ganesan
Nov 23 '18 at 9:02
add a comment |
You should be able to do this using a Ternary Operator.
The ternary operator lets you convert a somewhat long-winded if/else
statement into a single line. For example:
int a;
if(test) {
a = 1;
} else {
a = 2;
}
Can get converted into:
int a = test ? 1 : 2;
More complicated expressions can also be made by using multiple ternary expressions.
e.g.
int a;
if(testA) {
a = 1;
} else if(testB) {
a = 2;
} else {
a = 3;
}
Can be converted into this:
int a = testA ? 1 : // if(testA)
testB ? 2 : // else if(testB)
3; // else
Alternatively formatted as:
int a = (testA ? 1 : (testB ? 2 : 3));
In your scenario, the ternary operator can be used in the orderby
clause:
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby
((t1.TypeDefDesc == "Successful" &&
t1.TypeDefGroup == "ResponseType") ? 1 :
(t1.TypeDefDesc == "Failed" &&
t1.TypeDefGroup == "ResponseType") ? 2 :
(t1.TypeDefDesc == "Failed Attempt" &&
t1.TypeDefGroup == "ResponseType") ? 3 :
4) // Whatever the "else" group is
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
Check out the MSDN docs for more info.
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
add a comment |
You should be able to do this using a Ternary Operator.
The ternary operator lets you convert a somewhat long-winded if/else
statement into a single line. For example:
int a;
if(test) {
a = 1;
} else {
a = 2;
}
Can get converted into:
int a = test ? 1 : 2;
More complicated expressions can also be made by using multiple ternary expressions.
e.g.
int a;
if(testA) {
a = 1;
} else if(testB) {
a = 2;
} else {
a = 3;
}
Can be converted into this:
int a = testA ? 1 : // if(testA)
testB ? 2 : // else if(testB)
3; // else
Alternatively formatted as:
int a = (testA ? 1 : (testB ? 2 : 3));
In your scenario, the ternary operator can be used in the orderby
clause:
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby
((t1.TypeDefDesc == "Successful" &&
t1.TypeDefGroup == "ResponseType") ? 1 :
(t1.TypeDefDesc == "Failed" &&
t1.TypeDefGroup == "ResponseType") ? 2 :
(t1.TypeDefDesc == "Failed Attempt" &&
t1.TypeDefGroup == "ResponseType") ? 3 :
4) // Whatever the "else" group is
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
Check out the MSDN docs for more info.
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
add a comment |
You should be able to do this using a Ternary Operator.
The ternary operator lets you convert a somewhat long-winded if/else
statement into a single line. For example:
int a;
if(test) {
a = 1;
} else {
a = 2;
}
Can get converted into:
int a = test ? 1 : 2;
More complicated expressions can also be made by using multiple ternary expressions.
e.g.
int a;
if(testA) {
a = 1;
} else if(testB) {
a = 2;
} else {
a = 3;
}
Can be converted into this:
int a = testA ? 1 : // if(testA)
testB ? 2 : // else if(testB)
3; // else
Alternatively formatted as:
int a = (testA ? 1 : (testB ? 2 : 3));
In your scenario, the ternary operator can be used in the orderby
clause:
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby
((t1.TypeDefDesc == "Successful" &&
t1.TypeDefGroup == "ResponseType") ? 1 :
(t1.TypeDefDesc == "Failed" &&
t1.TypeDefGroup == "ResponseType") ? 2 :
(t1.TypeDefDesc == "Failed Attempt" &&
t1.TypeDefGroup == "ResponseType") ? 3 :
4) // Whatever the "else" group is
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
Check out the MSDN docs for more info.
You should be able to do this using a Ternary Operator.
The ternary operator lets you convert a somewhat long-winded if/else
statement into a single line. For example:
int a;
if(test) {
a = 1;
} else {
a = 2;
}
Can get converted into:
int a = test ? 1 : 2;
More complicated expressions can also be made by using multiple ternary expressions.
e.g.
int a;
if(testA) {
a = 1;
} else if(testB) {
a = 2;
} else {
a = 3;
}
Can be converted into this:
int a = testA ? 1 : // if(testA)
testB ? 2 : // else if(testB)
3; // else
Alternatively formatted as:
int a = (testA ? 1 : (testB ? 2 : 3));
In your scenario, the ternary operator can be used in the orderby
clause:
objTypeDefLst = (from t1 in objTypeDefLst join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId,0)
where t1.TypeDefGroup == strTypeDefGrp
orderby
((t1.TypeDefDesc == "Successful" &&
t1.TypeDefGroup == "ResponseType") ? 1 :
(t1.TypeDefDesc == "Failed" &&
t1.TypeDefGroup == "ResponseType") ? 2 :
(t1.TypeDefDesc == "Failed Attempt" &&
t1.TypeDefGroup == "ResponseType") ? 3 :
4) // Whatever the "else" group is
select new TypeDefinition {
ResponseTypeReason = (t1.TypeDefDesc +":" +t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid +"~" + t2.TypeDefcode
}).ToList();
Check out the MSDN docs for more info.
answered Nov 23 '18 at 6:37
AtinSkrita
958712
958712
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
add a comment |
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
Thank You @Atin
– Sivaraj Ganesan
Nov 23 '18 at 9:04
add a comment |
Done this by mywork. using ThenBy
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();
add a comment |
Done this by mywork. using ThenBy
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();
add a comment |
Done this by mywork. using ThenBy
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();
Done this by mywork. using ThenBy
objTypeDefLst = (from t1 in objTypeDefLst
join t2 in objTypeDefLst
on t1.TypeDefid equals TUtil.CheckInt(t2.ParentId, 0)
where t1.TypeDefGroup.ToUpper().Trim() == strTypeDefGrp.ToUpper().Trim()
select new TypeDefinition
{
ResponseTypeReason = (t1.TypeDefDesc + ":" + t2.TypeDefDesc),
ResponseTypeCode = t1.TypeDefid + "~" + t2.TypeDefcode
}).ToList();
objTypeDefLst = objTypeDefLst.OrderBy(a => a.TypeDefDesc == strTypeDefDescSuccess && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailed && a.TypeDefGroup == strTypeDefGrp)
.ThenBy(a => a.TypeDefDesc == strTypeDefDescFailedAtte && a.TypeDefGroup == strTypeDefGrp).ToList();
answered Nov 23 '18 at 8:58
Sivaraj Ganesan
168
168
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441251%2fconverting-order-by-with-multiple-case-statements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Probably easier to make a custom comparer than trying to do everything in one go. Bit hard to read otherwise
– MickyD
Nov 23 '18 at 6:48