Как преобразовать синтаксис запроса LINQ в синтаксис метода?(с объединением и множественным выбором) Проблема: перегрузки «где-нет» для + 3 параметров - PullRequest
0 голосов
/ 11 декабря 2018

Я пытаюсь понять лямбда-выражения с Linq, но я борюсь с преобразованием.Ниже приведен синтаксис запроса Linq, который работает просто отлично.

var systemUsersPoor =
            (from customer in customers
                join distributor in distributors

                    on new { customer.Location }
                    equals new{ distributor.Location }

                where customer.Location == "UK" &&
                      customer.Location==distributor.Location &&
                      customer.Supplier == "MoneyShits" &&
                      distributor.Products == "ShittyCrappyCraps"

                orderby customer.Name
                select new
                {
                    customerName=customer.Name , customerLocation=customer.Location, customerSupplier=customer.Supplier,
                    distributorName=distributor.Name, distributorProducts=distributor.Products

                }).ToList();

И вот здесь у меня есть неудачная попытка преобразовать его в синтаксис метода Linq ... Все работает дозаявление .Where утверждает, что у него нет определения для моих полей (.location, .Supplier) и распространителя

 var sysUserPoor2 = customers.Join       //from customer in customers Join 
        (
            distributors,                        //Join on distributors on customer.Location==distribution.Location
            customer=> customer.Location,        //Select the primary key (the first part of the "on" clause in an sql "join" statement
            distributor =>distributor.Location,  // Select the foreign key (the second part of the "on" clause)

            (customer, distributor) => new      //select statement
            {
                customerName = customer.Name,
                customerLocation = customer.Location,
                customerSupplier = customer.Supplier,
                distributorName = distributor.Name,
                distributorProducts = distributor.Products
            }
        )
            .Where
        (
             customer => (customer.customerLocation == "UK") &&
                         (customer.customerSupplier == "MoneyShits"),
            distributor => distributor.distributorProducts == "ShittyCrappyCraps",
                (customer, distributor) => (customer.customerLocation == distributor.Location)
            );

Запрос с кодом ниже работает, но яне знаю, как добавить остальное как-то ...:

.Where
        (
            customer => (customer.customerLocation == "UK") &&
                        (customer.customerSupplier == "MoneyShits")
        )

1 Ответ

0 голосов
/ 11 декабря 2018

Пожалуйста, попробуйте следующее.

var systemUsersPoor = customers.Join(distributors, 
                customer => customer.Location, 
                distributor => distributor.Location,
                (customer, distributor) => new {customer, distributor})
                 .Where(x => x.customer.Location.Equals("UK") && 
                  x.customer.Location.Equals(x.distributor.Location) &&
                  x.customer.Supplier.Equals("MoneyShits") && 
                  x.distributor.Products.Equals("ShittyCrappyCraps"))
                  .OrderBy(x => x.customer.Name)
                  .Select(x => new
                 {
                    customerName = x.customer.Name,
                    customerLocation = x.customer.Location,
                    customerSupplier = x.customer.Supplier,
                    distributorName = x.distributor.Name,
                    distributorProducts = x.distributor.Products
                  }).ToList();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...