0
當我在SQL運行此查詢我得到我想要的東西:爲什麼我的SQL結果不符合我的Linq結果?
SELECT Auckland_Park.Formative.[Formative Name]
FROM Auckland_Park.LearningUnit
INNER JOIN Auckland_Park.Formative
ON Auckland_Park.LearningUnit.ID = Auckland_Park.Formative.FK_LU
INNER JOIN Auckland_Park.Reference
INNER JOIN Auckland_Park.Course
ON Auckland_Park.Reference.FK_Course = Auckland_Park.Course.ID
ON Auckland_Park.LearningUnit.ID = Auckland_Park.Reference.FK_LU
WHERE Auckland_Park.Course.Name = 'BI'
我的結果:
Querying SQL Build
Report Develop
Java App Develop
Andriod App Set up
SharePoint Server
但是,當我與我使用LINQ到SQL我的C#應用程序,我的LINQ工作查詢看起來是這樣的:
//LINQ Query to fill Foramtive Name ComboBox
CTUDataContext data = new CTUDataContext();
var course = (from r in data.LearningUnits
join a in data.Formatives
on r.ID equals a.FK_LU
join f in data.References
on r.ID equals f.FK_LU
join g in data.Courses
on f.FK_LU equals g.ID
where g.Name == ("BI")
select new
{
formativeName = a.Formative_Name,
ID = a.ID
}
).ToList();
txtFormativeName.ItemsSource = course;
txtFormativeName.DisplayMemberPath = "formativeName";
txtFormativeName.SelectedValuePath = "ID";
這似乎是相同的,但我沒有變,我會繼續使用SQL查詢以上得到相同的結果。
更換什麼的LINQ查詢的結果? –
結果來自同一個表,但不是在我的WHERE子句下是「BI」。 –
你看過LINQ查詢生成的SQL嗎? –