使用 LLBLGen 进行内连接?

发布于 2024-09-07 19:58:15 字数 569 浏览 4 评论 0原文

我如何使用 LLBLGen 进行简单的连接?

table1 - clientTable(地址、电话等) table2 - 员工表(姓名等) table3 - clientEmployeeTable(clientid、employeeid)

我正在使用带有客户信息字段(地址、电话等)的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;

How could I do a simple join using LLBLGen?

table1 - clientTable (address, phone, etc)
table2 - employeeTable (name, etc)
table3 - clientEmployeeTable (clientid, employeeid)

I'm filling out a datagrid using the employeeId with fields for the client information (address, phone, etc) and I'm not sure how I could retrieve this using LLBLGen. I suppose I could create a stored procedure but maybe there's an easier way?

I'm completely new with LLBLGen.

I've been using stored procedures meanwhile but maybe there's a better way.

// 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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

私野 2024-09-14 19:58:15

欢迎来到 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;
}        

虽然这似乎需要很多代码来做一些基本的事情,但一旦您习惯了,代码几乎会自己编写,并且是比编写管道要快得多。你永远不会回去。

Welcome to LLBLGen! Great product once you're schooled up. One way to get information from a variety of joined tables is with a Typed List of your own design.

Your "my specific fields" get defined in the ResultsetFields. Your WHERE clause is defined with an IPredicateExpression. Your JOIN clauses are brilliantly handled by the IRelationCollection and the .Relations properties of each Entity.

When trying to get up to speed, running the SQL Server profiler (presuming you're using MSSQL) is key to see how your code changes in LLBLGen affect the actual SQL requested from the server. Managing all of the ()'s in the JOIN and WHERE clauses sometimes requires careful ordering but most of the time works on the first try. Here's a generic snippet that we use:

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;
}        

Your specific need:

SELECT (my specific fields)
FROM [client].[List] abl
    INNER JOIN [client].ClientGroup cg ON cg.ClientGroupId = abl.ClientGroupId

Would thus become:

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;
}        

While this seems like a lot of code to do something basic, the code almost writes itself once you're used to it and is vastly faster than writing plumbing. You'll never go back.

纸伞微斜 2024-09-14 19:58:15

您可能想创建一些“相关字段上的字段”。您可以将 ClientGroup 属性添加到 Client 实体以透明地访问它们。这仅适用于 (m:1) 关系中直接相关的字段。如果您想加入更深的层次,则必须使用类型化列表。

当您获取实体并且由于 where 语句而想要连接时,您可以使用关系来连接表并构建谓词。

问候

You probably want to create some 'fields on related fields'. You can add ClientGroup properties to the Client entity to access them transparently. This only works for directly related fields in an (m:1) relation. If you want to join deeper than that, you have to use typed lists.

When you fetch entities and you want to join because of the where statement, you can use relations to join the tables and build a predicate.

Regards

暮年 2024-09-14 19:58:15
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;
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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文