Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> 5.5.0 to 5.5.x Entity Edit
 

Pages: 1
Bugs & Issues
5.5.0 to 5.5.x Entity Edit
Page:1/1 

  Print all messages in this thread  
Poster Message
howes
User



Location:
Iowa City
Joined on:
16-Aug-2019 21:27:46
Posted:
2 posts
# Posted on: 16-Aug-2019 22:08:02.  
Using the DTO template I grabbed from this forum I am using the ToEntity() Method to grab a JSON input from a Web Api input and convert that to an entity and then edit values in the parent and child of that entity.

DTO Template:

https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=13256&HighLight=1

Since 5.5.1 and above when I try to edit the pk of the child (it is combination key), it will remove the entity from the graph. In the change log it appears that this was possibly addressed. (i.e pk changed entity might be out of sync, detach)

Code:

                var task = newTaskEditModel.ToEntity<TaskDTO, TaskEntity>(true, true);
                task.CustomNumber = _customNumberServices.GetNextCustomNumberLong(userDetails.TenantId, GetNextCustomNumberLongEnum.Task);
                task.CreateDate = task.UpdateDate = currentUtc;
                task.TableEntityTypeId = (short)EntityTypeEnum.Task;
                task.TenantId = userDetails.TenantId;
                if (!task.TaskStates.Any())
                {
                    task.TaskStates.Add(new TaskStateEntity
                    {
                        Description = string.Empty,
                        EntityStateTypeId = (int)TaskEntityStateTypeEnum.NotStarted
                    });
                }

                var taskState = task.TaskStates.Single();
                taskState.TenantId = userDetails.TenantId;

                //since TenantId is part of the pk the entity will be removed from graph

                taskState.CreateId = userDetails.UserId;
                taskState.CreateDate = currentUtc;
                taskState.TableEntityTypeId = (short)EntityTypeEnum.Task;


I have found that if I create a new child entity and then essentially clone it from the original child, then detach the original (detachFromGraph()), and then add the cloned one I get the expected results.

I have a bunch of code surrounding the editing of that pk and need some advice on what would be the suggestion solution, or if this is indeed a bug.

The combination primary key is basically for a multi-tenancy. pk = tenantId + pk of the entity.


Thanks for having a look,


Jon

Jon Howes  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8071 posts
# Posted on: 17-Aug-2019 08:58:52.  
Hi Jon,

Please help us figuring out some things to understand the problem:

- Describe the relation between TaskStateEntity and TaskEntity. What is the TaksEntity PK btw?

- Is this something that worked on v5.5.0 but now it doesn't? What exact runtime library version are you using right now?

- What is then changelog entry you saw about this?

- In the code you shared, if the taskState.TenantId field is part of the FK that points to TaskEntity PK, it shouldn't be necessary to set such field, because when you save the graph the PK will be propagated. Am I wrong?


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
howes
User



Location:
Iowa City
Joined on:
16-Aug-2019 21:27:46
Posted:
2 posts
# Posted on: 19-Aug-2019 20:11:25.  
Thanks for getting back to me

Task --> TaskState relationship is a 1 to many relationship
pks are taskStateID and tenantID and TaskId is the fk.

Editing the pk of a child entity (tenantId) WORKS in 5.5.0 and does not work in anything 5.5.1 and above

I may have been mistaken on the change log. It appears what I was referencing was for the Templates and not the runtime.

If I do not set the tenantId in the child entity and save it to the db. The child entity does pickup the new tenantId.

the tenantId is extremely important and that is why we were writing it. As I said, the code posted was working 100% in 5.5.0. When I upgrade the libs it will detach the child entity from the parent.

I am just trying to figure out was this designed behavior in 5.5.1 or was I just being overly cautious and there was no need to write the child pk (tenantId)

Best,


Jon

Jon Howes  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14484 posts
# Posted on: 20-Aug-2019 00:40:10.  
This is a designed behavior.

Please check FK-PK synchronization


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 20-Aug-2019 09:30:49.  
I think it's this change:
Quote:
Fix     Runtime Libraries 5.5     5.5.1     12-Dec-2018     When an FK field is re-used in multiple relationships and also is a PK field in another relationship, setting the FK field could cause a desync of the wrong related entities

Other than that, we didn't change anything (this fix was necessary as it was a bug).
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.