Case Statement inside LINQ


Example of a mock Case Statement inside LINQ wrapped inside the parens.


 var territoryInfo= (from e in  Franchisee_Zips
                            where e.AccountCode == accountcode

                            select new  Data.FullTerritory
                            {
                                AccountCode = e.AccountCode,
                                VendorName = e.VendorName,

                                Territory_Type = (e.TerritoryType == 0 ? "TAFS" :
                                e.TerritoryType == 1 ? "Purchased Territory" :
                                e.TerritoryType == 3 ? "Option" :
                                e.TerritoryType == 4 ? "Vendor" : "Unknown"
                                ),

                                OptionBegins = e.OptionBegins,
                                OptionExpires = e.OptionExpires,
                                Action = "Add"
                            });

Comments

Popular posts from this blog

Linq Exclude from separate list

Sorting Ascending and Descending

Linq Query Syntax vs Method Syntax