troubleshooting Question

LINQ -- easy CASE statement ?

Avatar of finance_teacher
finance_teacher asked on
.NET ProgrammingC#ASP.NET
11 Comments1 Solution425 ViewsLast Modified:
Currently below #1 works.

How can I change below #2 to be
simpler and work with "IN" statement
using ASP.net MVC4 C# ?
---------------------------------------------------------------------------------
#1
        public ActionResult Technician(string sabProjectID)
        {
            var myPOs =
            (from p in db.MAINT_WORK_REQ
             where
              p.WorkFlowStage == 6 && p.ProjectID == sabProjectID
             select p
            )
            ;
            return View(myPOs);
        }

---------------------------------------------------------------------------------
#2
        public ActionResult DisplayResults(string sabProjectID, string URLRole)
        {
            var myPOs =
              case
                WHEN URLRole='Inspector' THEN
                 (from p in db.MAINT_WORK_REQ
                  where
                   p.WorkFlowStage == 2 && p.ProjectID == sabProjectID
                  select p
                 )

               case
                WHEN URLRole='Lead' THEN
                 (from p in db.MAINT_WORK_REQ
                  where
                   p.WorkFlowStage in (6,7) && p.ProjectID == sabProjectID
                  select p
                 )

               case
                WHEN URLRole='Customer' THEN
                 (from p in db.MAINT_WORK_REQ
                  where
                   p.WorkFlowStage == 4 && p.ProjectID == sabProjectID
                  select p
                 )

            ;
            return View(myPOs);
        }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros