2

I have the following code that I've been able to cobble together by looking at a bunch of different sources online, however the below actually throws a null reference exception on the bottom line.

GroupAgentEntity agent = new GroupAgentEntity();

RelationPredicateBucket pred = new RelationPredicateBucket();
pred.PredicateExpression.Add(PredicateFactory.CompareValue(GroupAgentFieldIndex.GroupId, ComparisonOperator.Equal, groupId));
pred.PredicateExpression.Add(PredicateFactory.CompareValue(GroupAgentFieldIndex.IsPrimary, ComparisonOperator.Equal, true));
pred.PredicateExpression.Add(PredicateFactory.CompareValue(GroupAgentFieldIndex.BeginDate, ComparisonOperator.LessEqual, DateTime.Now));
pred.PredicateExpression.Add(PredicateFactory.CompareNull(GroupAgentFieldIndex.EndDate));

pred.Relations.Add(GroupAgentEntity.Relations.AgentSplitGroupEntityUsingAgentSplitGroupId);

IPredicateExpression preFilter = new PredicateExpression(AgentSplitGroupFields.Name == "Broker");

PrefetchPath2 pre = new PrefetchPath2((int)EntityType.AgentSplitGroupEntity);
pre.Add(AgentSplitGroupEntity.PrefetchPathAgentSplitGroup, 0, preFilter);

if (deep)
{
    pre.Add(GroupAgentEntity.PrefetchPathBroker);
    pre.Add(GroupAgentEntity.PrefetchPathCarrierBroker);
}

this.DataAdapter.FetchEntityUsingUniqueConstraint(agent, pred.PredicateExpression, pre);

What I'm attempting to do is join from the GroupAgent table to the AgentSplitGroup table as well as prefetch an entity of type AgentSplitGroupEntity. Unfortunately my experience with LLBLGen is rather limited (especially when it comes to predicate expressions).

Could anyone please provide any ideas as to why the above code is throwing a null reference exception on the bottom line? That, or if someone could help me to pull off the query I need in another way (but still using predicate expressions), I'd greatly appreciate it.

Note that I did the obvious thing and checked the parameters going to FetchEntityUsingUniqueConstraint(...) during runtime, and none of them are null.

KSwift87
  • 1,843
  • 5
  • 23
  • 40

1 Answers1

3

I'm not LLBLGen expert but you can change your PredicateExpression from:

pred.PredicateExpression.Add(PredicateFactory.CompareValue(GroupAgentFieldIndex.GroupId, ComparisonOperator.Equal, groupId));

with:

pred.PredicateExpression.Add(GroupAgentFields.GroupId == groupId);

Other operators work also. Null is DBNull.Value

But I think your problem is actually in Prefetch, it should look like this:

RelationPredicateBucket preFilter = new RelationPredicateBucket();
preFilter.Relations.Add(GroupAgentEntity.Relations.AgentSplitGroupEntityUsingAgentSplitGroupId);
preFilter.PredicateExpression.Add(AgentSplitGroupFields.Name == "Broker");
PrefetchPath2 pre = new PrefetchPath2((int)EntityType.AgentGroupEntity);
pre.Add(AgentGroupEntity.PrefetchPathAgentSplitGroup, 0, preFilter.PredicateExpression, preFilter.Relations);
iruzak
  • 46
  • 2
  • 2
    I moved past this a couple weeks ago but if I recall correctly, when I finally was able to get a hold of my boss, he said that I was going about my prefetch wrong. Unfortunately I can't remember what method this code was in to verify your answer code 100%, but I'm pretty confident you're right so I'm accepting your answer. Thank you. :) – KSwift87 Dec 09 '13 at 15:51