Chester wrote:
In these 2 lines of code:
p.Add(FriendEntity.PrefetchPathSendingUser, 0, pe);
p.Add(FriendEntity.PrefetchPathReceivingUser, 0, pe);
...what is the FriendEntity? I don't see a table called "Friend" in your query example.
Sorry, I "simplified" the example
The real code is this, which works now:
l = new FriendCollection();
IRelationPredicateBucket b = new RelationPredicateBucket();
b.PredicateExpression.Add(FriendFields.FkOwningUserId == mOwnerId);
b.Relations.Add(FriendEntity.Relations.UserEntityUsingFkFriendUserId, "u1").CustomFilter=new PredicateExpression(UserFields.IsEnabled.SetObjectAlias("u1")==true);
b.Relations.Add(FriendEntity.Relations.UserEntityUsingFkOwningUserId, "u2").CustomFilter=new PredicateExpression(UserFields.IsEnabled.SetObjectAlias("u2")==true);
IPrefetchPath2 p = new PrefetchPath2((int)EntityType.FriendEntity);
p.Add(FriendEntity.PrefetchPathFriendUser);
p.Add(FriendEntity.PrefetchPathOwningUser);
da.FetchEntityCollection(l, b,p);
All of that takes the place of a simple query:
select
f.*
from
friend f join user u1 on u1.userId = f.FkOwningUserId
join user u2 on u2.userId = f.FriendUserId
where
u1.isEnabled = 1 and u2.isEnabled = 1
Since I fixed it this is kind of a side note at this point, but I have to ask: what is the benefit of LLBL in a situation like this? It was incredibly complicated to build that query and incredibly easy to write it in SQL.