我想构建将在.net中使用的查询。下面你可以看到sql查询,任何人都可以给我等效的亚音速查询
SELECT DISTINCT a2.AccountID AS BID, a2.AccountName AS Brand FROM Account a INNER JOIN Account a2 ON a.ParentID = a2.AccountID WHERE a.AccountTypeID = 6 ORDER BY Brand
请帮帮我。
答案 0 :(得分:0)
SubSonic 2或3?
使用SubSonic,你总是有一个很好的后门。
它在2.x中称为InlineQuery,在3.x中称为CodingHorror
例如:
var result = DB.Query().ExecuteReader("SELECT DISTINCT
a2.AccountID AS BID,
a2.AccountName AS Brand
FROM Account a
INNER JOIN Account a2 ON a.ParentID = a2.AccountID
WHERE a.AccountTypeID = ?accounttypeid
ORDER BY Brand", 6);
如果由于语法检查和sql转换而希望保持流畅的界面。这是我能想到的另一种方法(SubSonic 2.2)
DataTable result = DB.Select(
"a1." + Account.Columns.AccountId + " as BID",
"a2." + Account.Columns.AccountName + " as Brand")
.From(Account.Schema.QualifiedName + " a1")
.InnerJoin(Account.Schema.QualifiedName + " a2",
"a2." + Account.Columns.account_id,
"a1", "a1." + Account.Columns.parent_id)
.Where("a1." + Account.Columns.AccountTypeId).IsEqualTo(6)
.OrderAsc("a2." + Account.Columns.AccountName)
.ExecuteDataSet().Tables[0];
但我从来没有这样做过,我还没有验证过。但也许它有效。