Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Answers


You can use SQL like case statement in LINQ query; I shared following example using switch case logic display leave types.

using (ApplicationServices SampleDbContext = new ApplicationServices())

            {

                var LeaveTypes = (from l in SampleDbContext.LeaveType

                        join e in SampleDbContext.User

                        on new { PID = l.AddedBy } equals new { PID = e.UserId}

                        select new

                         {

                           TypeId = l.TypeId,

                           TypeTitle=( l.TypeId == 1 ? "Medical" :

                                     l.TypeId == 2 ? "Sick" :

                                     l.TypeId == 3 ? "Casual Leave" :

                                     l.TypeId == 4 ? "Paternity Leave" :"Privileges"),

                                     LeaveTitle = l.LeaveTitle,

                                     Description = l.Description,

                                     AddedBy = l.AddedBy,

                                     UpdateBy = l.UpdateBy,

                                     CreatedDate = l.CreatedDate,

                                     UpdateDate = l.UpdateDate,

                                     CreatedBy = e.UserName

                                  }

 

                     ).ToList();

Share your answer


Share as a guest

Please subscribe me to the CodeChef4U.

By creating your new answer, you agree to the privacy policy and terms of service.