LLBLGenへようこそ!あなたが学校に通ったら素晴らしい製品です。結合されたさまざまなテーブルから情報を取得する 1 つの方法は、独自に設計した型付きリストを使用することです。
あなたの「特定のフィールド」は、ResultsetFields で定義されます。WHERE 句は IPredicateExpression で定義されています。JOIN 句は、各エンティティの IRelationCollection および .Relations プロパティによって見事に処理されます。
速度を上げようとするときは、SQL Server プロファイラー (MSSQL を使用していると仮定) を実行して、LLBLGen でのコードの変更がサーバーから要求された実際の SQL にどのように影響するかを確認することが重要です。JOIN 句と WHERE 句ですべての () を管理するには、慎重な順序付けが必要になることがありますが、ほとんどの場合、最初の試行でうまくいきます。以下は、私たちが使用する一般的なスニペットです。
private static DataTable GetTheGoodsOnEmployeeClients()
{
// Define the fields that you want in your result DataTable
ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(MyEntityFields.FieldName1, 0);
fields.DefineField(MyEntityFields.FieldName2, 1, "Field Name Alias");
// Add the WHERE clause to the query - "Condition" can be a literal or a variable passed into this method
IPredicateExpression filter = new PredicateExpression();
filter.Add(MyEntityFields.FieldName == "Condition");
// Add all JOIN clauses to the relation collection
IRelationCollection relations = new RelationCollection();
relations.Add(MyEntity.Relations.FKRelationship);
relations.Add(MyEntity.Relations.FKRelationship, JoinHint.Left);
ISortExpression sort = new SortExpression();
sort.Add(MyEntityFields.FieldName | SortOperator.Ascending);
// Create the DataTable, DAO and fill the DataTable with the above query definition/parameters
DataTable dt = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dt, 0, sort, filter, relations, false, null, null, 0, 0);
return dt;
}
あなたの特定のニーズ:
SELECT (my specific fields)
FROM [client].[List] abl
INNER JOIN [client].ClientGroup cg ON cg.ClientGroupId = abl.ClientGroupId
したがって、次のようになります。
private static DataTable GetTheGoodsOnEmployeeClients()
{
// Define the fields that you want in your result DataTable
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(ClientFields.ClientId, 0);
fields.DefineField(ClientFields.ClientName, 1, "Client");
fields.DefineField(ClientGroupFields.ClientGroupName, 2, "Group");
// Add all JOIN clauses to the relation collection
IRelationCollection relations = new RelationCollection();
relations.Add(ClientEntity.Relations.ClientGroupEntityUsingClientGroupId);
// Create the DataTable, DAO and fill the DataTable with the above query definition/parameters
DataTable dt = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dt, 0, null, null, relations, false, null, null, 0, 0);
return dt;
}
これは基本的なことを行うための大量のコードのように見えますが、慣れればコードはほとんどそれ自体を記述し、配管を記述するよりもはるかに高速です。あなたは決して戻らないでしょう。