我從這兩個表使用LINQ到實體獲取數據,主要foriegn密鑰基礎上的表之間存在的關係,結果集即將到來,但每行重複多次reult,但在Db沒有重複的行。不明白如何解決這個問題。ASP.net實體框架行返回重複
這裏是一段代碼:
StringBuilder sb = new StringBuilder();
string text = txtBoxSearch.Text;
OLSContainer ols = new OLSContainer();
var result = from tex in ols.COURSEs
from another in ols.UNITs
where tex.courseName.Contains(text) || tex.description.Contains(text) || another.unitName.Contains(text)
select new { tex,another };
foreach (var cours in result)
{
sb.AppendLine("<h2 id='" + cours.tex.courseID + "'><a href='admin.aspx?id='" + cours.tex.courseID + "''>" + cours.tex.courseName + "</a></h2>");
}
foreach (var cours in result)
{
sb.AppendLine("<h2 id='" + cours.another.unitID + "'><a href='admin.aspx?id='" + cours.another.unitID + "''>" + cours.another.unitName + "</a></h2>");
}
SQL查詢在探查器中的外觀如何?另外,課程和單元之間的完整關係是什麼?這是一對多嗎? – IronMan84