0

这是一个将数据分配给视图模型的 linq 查询。它工作得很好。

var data = (from C in db.CaseComplaints
                    where C.CasesID == caseid
                    select C.ComplaintCode).ToList().Select(x => new CaseComplaintsViewModel()
                        {
                            ComplaintCode = x.ComplaintCodeName,
                            ComplaintType = x.ComplaintType
                        }).ToList();

这是尝试执行连接并将数据分配给视图模型的代码。这没用。代码编辑器告诉我 x 没有 BranchName 的方法或定义

var data = (from branch in db.Branches
                    join customer in db.Customers 
                    on branch.BranchID equals customer.BranchID
                    where customer.BranchID == bid
                    select branch.BranchName).ToList().Select(x => new CaseResponsibleBranchViewModel()
                        {
                            BranchName = x.BranchName
                        });

我错过了什么?

4

1 回答 1

2

您已经选择了 BranchName,我想它是一个字符串,所以 x 没有 BranchName 属性:

var data = (from branch in db.Branches
                    join customer in db.Customers 
                    on branch.BranchID equals customer.BranchID
                    where customer.BranchID == bid
                    select branch.BranchName).ToList().Select(x => new CaseResponsibleBranchViewModel()
                        {
                            BranchName = x
                        });
于 2012-07-13T21:04:20.057 回答