Orm 使用LLBLGen的内部联接?

Orm 使用LLBLGen的内部联接?,orm,join,llblgenpro,Orm,Join,Llblgenpro,如何使用LLBLGen进行简单的连接 表1-客户表(地址、电话等) 表2-员工表(姓名等) 表3-客户员工表(客户ID、员工ID) 我正在使用employeeId填写一个数据网格,其中包含客户信息字段(地址、电话等),我不确定如何使用LLBLGen检索该字段。我想我可以创建一个存储过程,但也许有更简单的方法 我对LLBLGen完全陌生 我一直在使用存储过程,但也许有更好的方法 // in stored proc SELECT (my specific fields) FROM [client]

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

表1-客户表(地址、电话等) 表2-员工表(姓名等) 表3-客户员工表(客户ID、员工ID)

我正在使用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;

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

当您获取实体并且由于where语句而希望联接时,可以使用关系联接表并构建谓词


关于

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

当您获取实体并且由于where语句而希望联接时,可以使用关系联接表并构建谓词


问候

欢迎来到LLBLGen!一旦你接受了教育,你的产品就很棒了。从各种联接表中获取信息的一种方法是使用您自己设计的类型化列表

您的“我的特定字段”将在ResultsetFields中定义。WHERE子句是用IPRedicate表达式定义的。通过每个实体的DirectionCollection和.Relations属性,可以出色地处理连接子句

当尝试加快速度时,运行SQL Server profiler(假定您正在使用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;
}        

虽然这似乎需要很多代码来做一些基本的事情,但一旦你习惯了,代码几乎可以自己编写,而且比编写管道要快得多。你再也回不去了。

欢迎来到LLBLGen!一旦你接受了教育,你的产品就很棒了。从各种联接表中获取信息的一种方法是使用您自己设计的类型化列表

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;
您的“我的特定字段”将在ResultsetFields中定义。WHERE子句是用IPRedicate表达式定义的。通过每个实体的DirectionCollection和.Relations属性,可以出色地处理连接子句

当尝试加快速度时,运行SQL Server profiler(假定您正在使用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;
}        

虽然这似乎需要很多代码来做一些基本的事情,但一旦你习惯了,代码几乎可以自己编写,而且比编写管道要快得多。你再也回不去了。

我想我只是想弄清楚如何使用关系类型。我一直很难找到关于llblgen的好文档。除了llblgen自己的文档和用户支持论坛之外,我想我只是想弄清楚如何使用关系类型。我一直很难找到关于llblgen的好文档。除了llblgen自己的文档和用户支持论坛——这里经常引用它作为使用llblgen的主要原因之一:-)
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;