Guid ID in a join table being altered arbitrarily.

Posts   
 
    
Posts: 98
Joined: 09-Feb-2005
# Posted on: 24-Feb-2010 00:03:18   

UPDATE ----------- I just realized the LLBL is getting confused on the order of the fields. In the database, the fields are IdeaId, FacetId. The LLBL designer has them the other way around. Telling LLBL to look again didn't do it, but dropping the entity mapping, and recreating it did. Frustrating... UPDATE -----------

I'm using 2.6 Final from Oct 9.

I have 3 entities. Idea, IdeaFacet, and Facet.
The ids are guids.

Below, I've included the relevant pieces of a method from my partial IdeaEntity class.


public bool UpdateFrom(IdeaEntity ideaToUpdateFrom)
        {
            // remove all facets that aren't in the ideaToUpdateFrom
            var facetsToDelete = (from ideaFacet in IdeaFacets
             where !ideaToUpdateFrom.IdeaFacets.Any(idF=> idF.FacetId == ideaFacet.FacetId)
             select ideaFacet).ToList();
            facetsToDelete.ForEach(entity => IdeaFacets.Remove(entity));

            // add all of the facets that don't already exist.
            var facetsToAdd = (from ideaFacet in ideaToUpdateFrom.IdeaFacets
             where !IdeaFacets.Any(idF=> idF.FacetId == ideaFacet.FacetId)
             select ideaFacet).ToList();
            foreach (var I in facetsToAdd)
            {
                // Attempt 1: I.Idea = this;
                // Attempt 2: var newIdeaFacet = new IdeaFacetEntity(){Idea=this, FacetId = I.FacetId};
                //Attempt 3: IdeaFacets.Add(newIdeaFacet);
                //newIdeaFacet.FacetId = I.FacetId;
            }           
            return true;
        }

The ideaToUpdateFrom is coming in with values I want to use to overwrite my existing idea's data. Everything works fine, until I try to add related facets. (See the commented out code). Every one of my attempts to transfer the FacetId from the update entity to the persistent entity is failing. What's happening is that so long as I'm just dealing purely with an IdeaFacetEntity, unattached to an Idea, I can set the FacetId. As soon as I point it to my idea, the FacetId changes. In attempt 3, you can see that I tried setting the facetid after the idea. That set the facet, but unset the Idea.

What am I missing here?

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Feb-2010 03:42:19   

jeffdeville wrote:

UPDATE ----------- I just realized the LLBL is getting confused on the order of the fields. In the database, the fields are IdeaId, FacetId. The LLBL designer has them the other way around. Telling LLBL to look again didn't do it, but dropping the entity mapping, and recreating it did. Frustrating... UPDATE -----------

Try setting the _SyncMappedElementNamesAfterRefresh _flag to true, on LLBLGen Designer. Use it with care, as it could break your own custom code. Drop the entity and add it again is also a safe path.

I don't see 100% the real problem here. Please elaborate more on that. I don't know what your method is supposed to do, and in wich entity do you have the code? What is "this" in that context?

David Elizondo | LLBLGen Support Team