0
    public PrintCustomerAddress(PrintDocument doc, SEIKISHIRYOEntities context, ObservableCollection<PrintCustomerItem> customerForPrintPage)
    {

        this.context = context;
        this.customerForPrintPage = customerForPrintPage;

        printCustomerList = (from o in customerForPrintPage
                             select o).ToList();
        li = (from o in customerForPrintPage
              select o.CustomerID).ToList();
        //List<int> orderLst=getCustomerID(li);

        CustomerData = (from data in context.CustomerCompanyTables
                        where (from o in li select o).Contains(data.CustomerID)
                        orderby data.CompanyName ascending
                        select new CustomerCompanyTableMap
                        {
                            CompanyName = data.CompanyName,
                            CustomerID = data.CustomerID

                        }).ToList();

    }

如何按存储在默认排序 orderby customerID 的列表中的 customerID 序列对上述查询进行排序。

4

2 回答 2

1

检查这个:

CustomerData = (from _li in li
                join data in context.CustomerCompanyTables on _li equals data.CustomerID
                select new CustomerCompanyTableMap
                {
                    CompanyName = data.CompanyName,
                    CustomerID = data.CustomerID
                }).ToList();
于 2013-07-04T14:15:20.530 回答
1

我不确定您想要什么,但是如果您想按 CustomerID 列出您的数据,您可以执行以下操作:

var CustomerData = from data in context.CustomerCompanyTables
                where li.Contains(data.CustomerID)
                group data by data.CustomerID into result
                select result;

foreach (var customer in CustomerData)
{
    var customerID = customer.Key;

    foreach (var data in customer)
    {
        // do stuff
    }
}
于 2013-07-04T14:23:11.993 回答