使用 LLBLGen 多次连接到同一个表
我有一个表,我们称之为 Widget,其中包含 person1id 和 person2id(除其他外)。 (是的,我想我应该设置一个 NN 关系表,但到目前为止,我们在一个小部件上从来没有超过 2 个人。)
Person1Id(当然还有 person2id)链接到一个人表,并且有另一个链接到 PersonDetail桌子。
如何查询包含 2 个人和 2 个个人详细信息的小部件列表,并根据个人详细信息字段进行过滤?如果我的小部件中只有一个 personid,我会这样做:
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(WidgetEntity.Relations.PersonEntityUsingPerson1Id);
relationsToUse.Add(PersonEntity.Relations.PersonDetailsEntityUsingDetailId);
PredicateExpression filter = new PredicateExpression(new FieldCompareValuePredicate(PersonDetailsFields.ModifiedDate, ComparisonOperator.GreaterEqual, startdate)); //whatever
var list = new WidgetCollection();
list.GetMulti(filter, relationsToUse);
那么如何获取第二个关系呢? relationsToUse.Add(WidgetEntity.Relations.PersonEntityUsingPerson2Id);
?
我正在使用 LLBLgen 2.6 和 .net 3.5。我确实在此处看到了相关问题,但它不一样。
I have a table, let call it Widget, with (among others) person1id and person2id. (Yes, I suppose I should have setup a N-N relation table, but so far we never have more than 2 persons on a single widget. )
Person1Id (and person2id of course) are linked to a person table with yes another link to a PersonDetail table.
How can I query a list of Widgets with 2 persons and 2 persondetails, filtering on a persondetail field? If I had just one personid in my widget I would do:
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(WidgetEntity.Relations.PersonEntityUsingPerson1Id);
relationsToUse.Add(PersonEntity.Relations.PersonDetailsEntityUsingDetailId);
PredicateExpression filter = new PredicateExpression(new FieldCompareValuePredicate(PersonDetailsFields.ModifiedDate, ComparisonOperator.GreaterEqual, startdate)); //whatever
var list = new WidgetCollection();
list.GetMulti(filter, relationsToUse);
So how do I get the second relation in? relationsToUse.Add(WidgetEntity.Relations.PersonEntityUsingPerson2Id);
?
I'm using LLBLgen 2.6 with .net 3.5. I did see the related question here but it's not the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要为您添加的每个关系指定一个别名 - 如果我没记错的话,LLBLGen 文档文件中有一些内容谈到了这一点。
这取自 LLBLGen 2.6 文档,对于“高级过滤”,您可以看到如何两次加入同一个表并使用别名来控制过滤器:
...解决方案是为添加到关系中的实体添加别名RelationCollection,并且还在谓词中使用相同的别名。如果省略别名,则它被视为没有别名,并且如果您在先前添加的关系中为同一 RelationCollection 中的实体设置了别名,则它将被视为连接列表中的不同实体。因此,在第一个关系中将 Customer 别名为“C”,而在第二个关系中,您没有为 Customer 指定别名,您将在联接列表中获得 2 倍的 Customer 实体。因此请谨慎使用别名。
我们的 Customer 示例和带有两个 City 谓词的两个 Address 实体将生成以下代码。还要注意谓词中别名的使用。
You just need to specify an alias for each of the relations you add - if I remember correctly theres something in the LLBLGen doc file that talks about this.
This is taken from the LLBLGen 2.6 docs, for "advanced filtering", you can see how to join onto the same table twice and use aliases to control your filters:
...The solution is to alias the entities in the relation added to the RelationCollection, and also to use the same alias in a predicate. If you omit an alias, it is considered not aliased and if you have aliased an entity in an earlier added relation to the same RelationCollection, it will be considered a different entity in the join list. So aliassing Customer to "C" in the first relation and in the second relation you do not specify an alias for Customer, you'll get 2 times a Customer entity in the join list. So use aliassing with care.
Our example of Customer and the two Address entities with the two City predicates will result in the following code. Notice the alias usage in the predicates as well.