I can’t post a full working example right now, but I was hoping someone would have an idea of what might be going on here. (I’ll try to toss together a small working sample later this evening if no one can explain what might be happening from what’s posted)
List<CVENT.Idea> ideas = ideaDAL.GetList(filter);
foreach (CVENT.Idea idea in ideas) // Setup foreign key mapping
BuildRelationships(idea, 8);
// Breakpoint set on next line.
ideas = (from idea in ideaDAL.GetList(filter)
where IdeaSatisfiesCriteria(idea,filter)
select idea).ToList();
// I then Run To Cursor to This Line so I get a before and after the previous line.
foreach (CVENT.Idea idea in ideas) // Setup foreign key mapping
BuildRelationships(idea, 8);
return ideas;
So I am loading some ideas from our DAL layer. This works fine. I then have a “BuildRelationships” function that assigns some Lambda expressions to Func delegate variables for each idea.
In Build Relationships function
private CVENT.Idea BuildRelationships(CVENT.Idea idea, int userID)
{
idea.MapComments = thisIdea => commentBLL .GetList(thisIdea.IdeaID, userID).ToList();
return idea;
}
In my idea entity
public Func<Idea, List<Comment>> MapComments { get; set; }
This is a read only implementation of a Foreign Key Mapping Pattern where I am injecting the initialization for the foreign keys into my entity so that it can lazy load the foreign entity on demand.
The problem is that after the line I have the first breakpoint set on all of the Mapping variables are cleared to null (hence the second call to remap the relationships). I am guessing it has something with the creation of a new list because of ToList(), but what I don’t understand is why the Mapping delegate variables aren’t getting carried over with the rest of the properties. Any ideas?
(IdeaSatisfiesCriteria only does comparisons nothing is getting changed within the function.)
All the mappings disappear because you are re-querying your ideas from the DAL instead of taking the existing list to which you applied the mappings. You probably intended to do this: