C# How do I use a variable in a Linq select statement using Query Syntax

I'm trying to get the name of item but I'm having to hard code the locale in the select statement. This is my code

private void GetOrder(Root Wix)
    {
        string locale = Wix.restaurant.locale;
        List<Item> menu = Wix.menu.items;
        List<OrderItem> orderItems = Wix.order.orderItems;
        foreach (var orderItem in orderItems)
        {
            string itemId = orderItem.itemId;
            string itemName = (from m in menu  where m.id==itemId select m.title.en_GB).FirstOrDefault();

            int count = orderItem.count;
            string comment = orderItem.comment;
            int price = orderItem.price;
        }

        string orderComment = Wix.order.comment;
        int totalPrice = Wix.order.price;
    }

How can I replace the hard coded "en_GB" in select m.title.en_GB to the locale value returned in the string locale = Wix.restaurant.locale ?



Read more here: https://stackoverflow.com/questions/66277949/c-sharp-how-do-i-use-a-variable-in-a-linq-select-statement-using-query-syntax

Content Attribution

This content was originally published by Paul Clark at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: