欢迎来到 LLBLGen!受过教育的好产品。从各种连接表中获取信息的一种方法是使用您自己设计的类型化列表。
您的“我的特定字段”在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;
}
虽然这似乎需要很多代码来做一些基本的事情,但一旦你习惯了它,这些代码几乎可以自己编写,而且比编写管道要快得多。你永远不会回去。