日期:2014-05-20  浏览次数:20924 次

LINQ to ENTITY 一个多表查询
下面是我的查询语句
C# code

            List<Query360UnitDataContract> list = (from RentalUnit in TempRentalUnitEntityList
                                                   join RentalContract in TempRentalContractEntityList on RentalUnit.RentalID equals RentalContract.RentalID
                                                   join Account in TempAccountEntityList on RentalContract.AccountID equals Account.AccountID
                                                   join Unit in TempUnitEntityList on RentalUnit.RefRecordID equals Unit.UnitID
                                                   join Company in TempCompanyEntityList on Unit.PropertyCompanyID equals Company.CompanyID

                                                   select new Query360UnitDataContract
                                                   {
                                                       UnitID = Unit.UnitID,
                                                       UnitNo = Unit.UnitNo,
                                                       BuildUpArea = Unit.BuildUpArea,
                                                       RecordStatus = Unit.RecordStatus,
                                                       AccountName = Account.Name,
                                                       CompanyName = Company.Name,
                                                       Price = Unit.Price
                                                   }).ToList<Query360UnitDataContract>()




这里是我的SQL语句
SQL code

SELECT Unit.UnitID,Unit.UnitNo,Unit.BuildUpArea, 
Unit.RecordStatus,Account.Name, Company.Name,Unit.Price
FROM Lease.RT_RentalUnit as RentalUnit 
join Lease.RT_RentalContract as RentalContract on RentalUnit.RentalID = RentalContract.RentalID
join Lease.CF_Account as Account on RentalContract.AccountID = Account.AccountID
join Lease.MC_Unit as Unit on RentalUnit.RefRecordID = Unit.UnitID
join lease.CF_Company as Company on Unit.PropertyCompanyID = Company.CompanyID 




我用SQL 可以查询出数据,但用LINQ 却查不出来,能帮忙看看是什么原因吗?

------解决方案--------------------
what does this mean? "TempAccountEntityList"
------解决方案--------------------
给你个工具,LINQPad,自己去看吧。