Why we use ChangeAwareList and ChangeAwareMap - atg

Could you please let me know what is the use of ChangeAwareList and ChangeAwareMap in atg? What problem does it try to solve. I tried reading the documentation but could not find any details regarding the same.

ChangeAwareList and ChangeAwareMap ensure when the parent RepositoryItem has relationships added or removed, when the parent item is updated, that the new relationship are insert/deleted from the database.
If ChangeAwareList and ChangeAwareMap were not used, then when the parent item were being updated/stored to the Repository/database, then you would have to have some logic to loop through each of the existing relationships and compare them to the updated relationships to determine which relationships need to be removed from the database. This is more cumbersome and does not perform as well as the implementation that is "change aware".
This is an example of the Observer design pattern.

Related

Navigation Properties between Views in EF Code First

Is it possible to define navigation properties between Views in EF with code first? Please, note that I do not need any tool generating any code for me. I would like to know whether or not this can get done and the logic behind this.
Suppose you have a project in which you will only work with views. No data will be created, updated or deleted (at least by you). All you need to do is queries and all you have are views.
Suppose now a second scenario in which you can also have tables, but your purpose is only to visualize data (you will treat them as views). However, there is not always a foreign key referencing the primary key of the parent table in relationships.
My question is: Can I define navigation properties in these scenarios? Or do I have to relay on joins only?
Thanks!
I'm working on this myself. Everything I'm reading indicates you have to manually edit the .edmx files so that the views are considered tables and manually add the nativation properties yourself. Downside is if you resync against the database you have to repeat the process all over again.
Re:
https://social.msdn.microsoft.com/Forums/en-US/dcbdfe52-6ba7-4e75-94aa-51c88b57635c/adding-navigation-property-to-a-view?forum=adodotnetentityframework

iOS Core Data - Relationships

I’m guessing this is a basic question and hopefully someone will be able to point me in the right direction to some sample code, so my question….
I want/have created a core data model that has a parent child relationship, one to many, what I would like to know is what is the correct way to insert child records if the parent already exists. What I’m struggling to understand is how the parent relationship is created when only inserting child records.
Hopefully this makes sense, thanks for any help.
Here You have a series of 3 tutorials: RayWenderlich: Core Data Tutorial
Here a sample app: iPhoneCoreDataRecipes with a more complex data model
Here a Core Data tutorial – One to Many Relationship
Sorry I not respond to your question in his totally. I'm also starting with Core Data, so If You find a good intermediate tuturial, please let me know.
EDIT:
A nice article: Core Data Class Overview
So you'll have Parent and Child. Child will contain a Parent *parentobject while Parent will contain a NSSet *children. Whenever you set the relationship correct in the Datamodel the relationship will be applied automatically when you fill the children set with Child objects.
Please check Articles here

CoreData (IOS) Unique Constraint on Multiple columns?

Is it possible to, in CoreData for an iPhone app, have a Unique Constraint on Multiple columns?
For example:
have Event, EventItems, Items entities
the EventItems entity has a column ORDER
so the ORDER column for an EventItem should be unique for all it's instances relating to the same EVENT
So questions are:
How could I setup this constraint in coredata?
If it's not directly support any suggestions re how to put in place programmatically?
To do
For any core data constraint that operates on more then a single managed object at once you want to look at implementing:
- (BOOL)validateForDelete:(NSError **)error
- (BOOL)validateForInsert:(NSError **)error
- (BOOL)validateForUpdate:(NSError **)error
(I normally have core data make a .h and .m file for the entity, and then make my own category for things like this so I don't have as much work if I change the entity a little later)
If you have something that only needs to make sure values in a single managed object are correct you can use -validate<Key>:error:
To do what you are looking for I would make EventItems' validateForInsert/validateForUpdate
call a common method (maybe validateUniqueOrder). In that method I would use the relationship from EventItems to Event, and then fetch all the EventItems relating to the Event, and then check for uniqueness. I have fairly small sets of relations, so I didn't bother with anything fancy, but if you have a lot of event items associated with given events you might look into NSFetchRequests' setPropertiesToFetch method. Or maybe you can come up with a query that can directly search for duplicated values (I never could, so if you do, reply here to enlighten me).
How could I setup this constraint in coredata?
You control what goes into the data store, so you can impose any constraints you like, no matter how complex. But Core Data is not a database, and it doesn't implement the kinds of automatic constraints that you typically find in a RDBMS.
If it's not directly support any suggestions re how to put in place programmatically?
I'd do a check at the point in your code where you create or modify the affected object. In your case, you could create a custom setter for EventItem's 'order' property that compares the proposed 'order' to that of all the other EventItems related to the same event. Or, you might put the check in Event, and use an appropriate accessor to check any new EventItems as they're added.
Unique Constraints make sure that records in an Entity are unique by the given fields. But unique constraints along with To-Many relationship leads to a lot of weird issues while resolving conflicts.
e.g. “Dangling reference to an invalid object.”
This post is basically focused to a small problem that may take days to fix.
http://muhammadzahidimran.com/2016/12/08/coredata-unique-constraints-and-to-many-relationship/

Callbacks on entity on created/updated

I would like to know when entities in a certain database table are either created or updated. The application is essentially a CMS, and I need to know when changes are made to the content so that I can reindex them for searches.
I know that the autogenerated LINQ to EF class has overridable methods for when certain fields change, but I need to know when the whole object is created/updated, not just a single field. I tried putting it in OnCreated, only to find that meant OnObjectInitialized and not OnObjectInsertedIntoDBTable xD
I did some searching and came across this link. The "Entity State" section looks like its what I want, but I'm not sure how to use this information. Where do I override those methods?
Or perhaps there is a another/better way?
(I also need to know this for another part of the system, which will send notifications when certain content is changed. I would prefer this code to execute automatically when the insert/update occurs instead of placing it in a controller and hoping hoping I always call that method.)
You need to get ObjectStateEntry(s) from the ObjectStateManager property of the ObjectContect.
var objectStateEntries = this.ObjectStateManager.GetObjectStateEntries();
This entries contain every object state you've pulled down per context and what kind of actions where performed on them.
If you are using EF4 you can override the SaveChanges method to include this functionality. I've used this technique to audit every change that occurs in the database instead of triggers.

RIA services presentation model with 1-many or many-many relationships

I'm trying to get a presentation model (discussed here and here) working in RIA. All the examples I can find are simple, flat data entities with no 1-many or many-many relationships, which are what I can't get working - specifically, on updates and inserts into associative relationships.
Queries I can get working fine - I have my presentation classes marked up with Association attributes (and Include attributes, where appropriate), and I have a good understanding about how data is loaded into the client side and maintained there as entities. I also have inserts of new entities covered. However, I'm experiencing the following problems. For the following examples, assume we have simple Album and Artist entities, where an Album has a single artist and an Artist can have zero to many albums. Both have a Name property.
On the client side, if I do myArtist.Albums.Add(anAlbum) or myArtist.Albums.Remove(anAlbum), nothing happens. HasChanges returns false. (Note that myArtist and anAlbum were obtained solely in code by loading the entities and iterating to get references to specific entities: I'm not doing anything in UI or with DomainDataSources yet, just dinking around).
If I update the Name on an Artist and SubmitChanges, when the Update method gets called on the server, the Albums collection is null.
Does anyone have any suggestions, or can you point me to an example that uses more complex objects?
EDIT (keeping the above for posterity): Alright, it appears that the second issue (a reference to an entity or a collection of entities showing as null when Update gets called on the server) exists because the child entites aren't marked as Changed and so they aren't being serialized and sent back. I know you can force that to happen by using [Composition] and I have gotten it to work that way, but this is not a compositional relationship and I want both entities to be "top-level" entities. How can I mark an entity as changed?
The problem was that my [Association] attributes weren't correctly defined. I didn't realize that the association's Name property has to be the same on both sides of the association. When the names are the same and you do a build, the generated code on the client uses a different constructor for the EntityCollection used by the "parent" to refer to the "children" than it does if the associations aren't set up right. The new constructor takes callbacks that do a little bit of extra handling when you call Add and Remove on the collection - specifically, they take the child entity you are adding or removing and modify the property on it that refers to its parent so that everything remains in sync: the collection you removed the object from, the collection you added it to, and the object's reference to its parent.