如何使用LLBLGen进行简单的连接?
table1 - clientTable (地址、电话等) table2 - employeeTable (姓名等) table3 - clientEmployeeTable (客户端etc、员工etc)
我正在使用带有客户端信息(地址、电话等)字段的employeeId填充数据网格,但我不确定如何使用LLBLGen检索该数据网格。我想我可以创建一个存储过程,但也许有一种更简单的方法?
我对LLBLGen完全陌生。
在此期间,我一直在使用存储过程,但也许还有更好的方法。
// in stored proc
SELECT (my specific fields)
FROM [client].[List] abl
INNER JOIN [client].ClientGroup cg ON cg.ClientGroupId = abl.ClientGroupId
// in code
DataTable dt=RetrievalProcedures.GetEmployeeNote(EmployeeId);
rgridNotes.DataSource = dt;发布于 2010-07-02 14:48:46
你可能想要创建一些“相关字段”。您可以将ClientGroup属性添加到客户端实体以透明地访问它们。这只适用于(m:1)关系中的直接相关字段。如果你想进行更深层次的连接,你必须使用类型化列表。
当您获取实体并且由于where语句而想要连接时,您可以使用关系来连接表并构建谓词。
问候
发布于 2010-10-09 04:32:25
欢迎使用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;
} 虽然这看起来像是做一些基本工作的大量代码,但一旦您习惯了,代码几乎会自行编写,而且比编写管道快得多。你再也回不去了。
发布于 2018-03-05 22:47:10
Use LinqMetaData
LinqMetaData metaData = new LinqMetaData();
if you use adapter mode
LinqMetaData metaData = new LinqMetaData(adapter);
var result = from a in metaData.TableA
join b in metaData.TableB on a.Key equals b.Key
where a.OtherField == value
select a;https://stackoverflow.com/questions/3159602
复制相似问题