Update parent object from child object - triggers

I have one parent object that is group and another child object that is individual. I have to concatenate two field individual name and designation of child object and update parent object field that is description using after trigger. I fail in this.
I tried but not work

Related

Locust: how to share data between two different types of users

I have a system where there are two types of entities - parent and child.
When a parent goes into a particular state, it creates one or more child entities and the child entities then go through their state changes independent of each other and the parent. The main thing to note is that when a parent spawns off a child, he also assigns an id to it and the child has to use that id while going through the state changes.
So, in my locustfile, I created two different classes as below:
class ParentLocust(Locust):
task_set = ParentTaskSet
class ChildLocust(Locust):
task_set = ChildTaskSet
My question is that when an instance ofo the ParentLocust issues the REST call which leads to the creation of a child entity, how can the id of the child entity be conveyed to a ChildLocust instance?
My first thought was to use a global dictionary, where the key is the parent_id and the value is a list containing the different child_id. Now, an instance of the ChildLocust gets assigned a random child_id by doing a random lookup in the dictionary and then removes it from the dictionary as well (so that no other ChildLocust gets assigned the same child_id). But I am not sure if this is correct, because there are two many instances (parent as well as child) accessing the same dictionary at the same time.

How to query for results by specifying a condition on a relationship in Core Data?

I have two entities Parent and Child connected by an optional one-to-many relationship. I am trying to write a predicate that will allow me to do the following:
Only retrieve Parent objects that have Child objects in which a specific attribute is set, eg. name = 'John'
Retrieve Parent objects in which only the selected Child objects are populated. So in the above case, the childSet property would only contain John but not Mary or Peter.
Is there a way to do this in Core Data?

MongoDB storing and querying child objects

I've two different object with same father. I want to store them in the same collection, but I want to be able to retrieve each object separately.
for example if these are my objects:
I want to retrieve all of FirstChild objects without retrieving any SecondChild Object.
Is there any way other than adding a type field to the father object, to retrieve them?
Assuming first child and second child are different types stored in different fields of the father object (father is a composition of first and second child)
datastore.find(FatherObject.class).retrievedFields(false,"secondChildField")
will get everything except secondChildField or
datastore.find(FatherObject.class).retrievedFields(true,"firstChildField")
will bring only firstChildField.
When you create your query, pass in the class reference of the type you want: datastore.createQuery(SecondChild.class). Morphia, by default, tracks the class type of the document so it can filter by that type.

Entity Framework - updating sum of related entity collection property values on parent entity

How can I effectively update the parent EntityObject property which is there to expose only the sum of the related child entity collection property? I need an update in parent any time there is a change of property value in any of the child entity.
An example: I have a parent EntityObject "Company" and a collection of related child objects "Employee". These have association in EF between each other (one Company to collection of Employees). In Employee partial class I have added a custom calculated property "Salary" and in a Company partial class I have added a custom property "TotalSalaries".
Now, if any Employee Salary property is updated to a new value, I want to immediately update the Company object property TotalSalaries value.
Whenever the Employee property changes and if then I always run a full query inside the Company object like:
TotalSalaries = Me.Employees.Sum(Function(x) x.Salary)
...that looks like a highly inefficient thing to do, especially if all custom property values in Employee class are changed by looping for example (the above query is run over and over again).
Can the property update be reflected in the parent class more efficiently?
I figured this out. On the Employee class, I can capture the original property value in a class-level PropertyChanging event:
Private Sub employee_PropertyChanging(ByVal sender As Object, ByVal e As PropertyChangingEventArgs) Handles Me.PropertyChanging
Dim propBeignChanged As String = e.PropertyName
If propBeignChanged = "Salary" Then
OriginalValue = CType(sender, Employee).Salary 'store the current value temporarily to a variable
End If
End Sub
And then I can get the new value either in a class-level PropertyChanged event or the property-specific On[Property]Changed event, calculate the difference against the temporarily stored original value and pass the difference to the parent object.
Private Sub OnSalaryChanged()
Dim diff as Double = Me.Salary - OriginalValue
'and finally pass diff to the parent object for updating its total...
End Sub
I believe this must be a much faster approach than querying the whole EntityCollection.

Adding object to navigation property collection creates new entity

I am using Entity Framework 4.
I am trying to associate a new entity with an existing entity. The system ends up creating a new child entity when in fact I just want to add a reference to the child object to the parent.
There is a many to many relationship between the two entities so I cannot simply set the FK property of the parent entity. I have tried parent.ChildCollection.Add(child) which simply creates a new child object in the database. This is what I am trying to avoid.
I must be doing something obviously wrong.
thanks
updated code sample
Code sample for my Self-Tracking-Entities that I have to do client side
Right now I have something like this to get all children from server then loop through to find the one i want, then add it to the object collection
List<Service.Child> childs = _client.GetChildren();
I have to loop through that collection to find the right one to add to the parent.childs collection ie.
List<Service.Child> childList = new List<Service.Child>();
foreach (Service.Child child in childList) {
if (child.ChildId == childId)
childList.Add(child);
}
contact.Childs = childList;
If an entity originally came from the database and has its own EntityKey properties populated, using Add to link it to another entity will change its EntityState to Added. Even though it is a preexisting entity, SaveChanges will create an insert command for this entity. You should consider using Attach instead:
parent.ChildCollection.Attach(child);
Using the Attach method, you can define relationships between entities that already
exist in the ObjectContext but that have not been connected automatically.