WCF RIA SERVICE How many object are sent across network - wcf-ria-services

I have Collection of objects. They are have reference to the same object. Is it one object will be send across network?
UPD
Hello. I have Collection of objects. They are have reference to the same object. Is this same object will be send across network in one instance or for each object in Collection?(Collection is send too)

Each object is sent only once.
For example, you have a parent-child set of objects. Five of the child objects refer to the parent. When sending the set of children to the client, the parent object is serialized into the response only once.
The [Key] attribute is used to identify an object as unique. Unique objects are serialized once per request/response. The WCF RIA client library unpacks the parent object from the response and re-establishes the parent-child relationship using the information in the [Association(...)] attribute.

If you send the collection , all objects are sent across the network.
If your doubt it's about objects size, you can use JSON protocol to exchange data instead of XML.

Related

Return a modified object in a REST PUT

I am implementing a REST api for setting and retrieving a resource.
I have been asked to implement a strange PUT, whereby a JSON object is stored, while another JSON object is returned.
PUT /object/{id} - stores the object with a specified identifier, and returns properties about that object in a different object
The upstream team is requesting this purely for convenience - one action (the storage of the object) is always followed by a request of derived information (based on the contents of the object).
In my mind, in a RESTful api, these would be two calls: one to store the object, then another to retrieve some data about that object id.
PUT /object/{id} - stores the object with a specified identifier
GET /object/{id} - retrieves the object with a specified identifier
GET /object/{id}/properties - retrieves properties about the object
One thought I had was to expand the object itself to include space for the "derived properties", so that the PUT sends in an object that is essentially incomplete, and then the returned object is returned with the completed properties data. I have seen many apis branded as RESTful that return a copy of the actual object stored, so this is the basis for this approach, but I have not seen an api that appended additional data.
What is the RESTful approach to obtain this derived data?

What are the differences of using value proxies for my entities instead of entity proxies?

So far i understand that i will have no more need to define an #version field in my entitites and no more need to use an entity locator. And for value proxies i will have to usenormal editors. Any other diffrences, advantages, disadvantages? What about in the context of using request factory in conjunction with spring
The main difference is that with EntityProxy, the client can send a diff of changes rather than the entire object graph. This is made possible because EntityProxys have an identity, so the server can fetch the identity from the datastore and then apply the diff/patch sent from the client, and only then the entity will be passed to your service methods.
With ValueProxy you basically have an equivalent of GWT-RPC: the object is reconstructed from scratch on the server, and not associated with your datastore (in the case of JPA for instance, it's not attached to the session). Depending on your datastore API, this can make things more complex to handle in your service methods.
Other than that, you'll also lose the EntityProxyChange events.

Creating a Breeze Entity including navigationproperties using manager.createEntity throws exception

Scenario:
I use breeze for querying in our SPA and raw http methods for POST PUT DELETE methods.
A POST method on a resource returns the created resource including it's created childobjects.
I want to attach this created resource to the beeze entity manager.
I've tried adding the entity using
manager.createEntity('Driver', data, breeze.EntityState.Unchanged);
where the data object contains the driver resource and an array of related child entities.
But get an exception: "Collection navigation properties may NOT be set."
Do I have to create the local entity by hand and attach the child entities or does breeze support this scenario?
The reason for this exception is that the 'createEntity' method creates the entity and then assigns your 'data' to it, but for any collection navigation properties the collection already exists and Breeze won't allow you to replace it. This was a deliberate choice for existing entities where other parts of the application might hold a reference to the collection, but is overkill in this case where you are the 'first' to access the collection. For now, the workaround is to update any navigation collections instead of replacing them.
So the simplest way to do this is to call the createEntity method without any collection data properties, and then push data into your collections
var driver = manager.createEntity('Driver', dataWithoutCollections, EntityState.Unchanged)
// then update collection properties by pushing into them.
trafficFines.forEach(function(trafficFine) {
driver.trafficFines.push(trafficFine); // or use push.apply
};
Note that adding to an entity's collection properties will not cause an EntityState change so this should be sufficient.
Based on this issue, I will add a feature request to suppress this exception in the case where you are calling the 'createEntity' method, since there is no danger that some other part of the application has already had access to the new entity.

Can I serialise a NSManagedObject?

I need to send an object (NSManagedObject (NSMO) subclass) up to a web service and retrieve it later. I was hoping I could somehow serialise it, but I'm hoping not to have to jump through the encoding hoops.
I can convert a simple NSMO object into a dictionary using:
[instance dictionaryWithValuesForKeys:instance.entity.attributesByName.allKeys];
However, my NSMO is a number of levels deep in terms of relationships to other NSMOs. What would be the best way to create a full serialised version of the object?
If you want to do this in a general way, you could write a recursive method serializedDictionary (either in a subclass of NSManagedObject or in a category) which:
Creates an empty NSMutableDictionary.
For each property, adds the key and value to the dictionary.
For each relationship, adds the relationship name as key and then calls serializedDictionary on the object and adds that as the value. If it's a to-many relationship, you'll have to put those values in an NSArray.
Note that if it's at all possible for a child object to be related back up to a parent (which is very possible if you have inverse relationships like Core Data recommends) you will either need to whitelist the relationships you save (easier) or pass along a set to keep track of which objects have already been serialized, so you don't encode them again (harder, I don't recommend this).

iPhone: How to manage Core Data relationships by foreign keys

I have an app working with databases on both server side and iOS client side. And I use a HTTP services to sync between SQL Server on server side and Core Data on iPhone.
I have some Core Data objects like this:
ProductGroup
Attributes:
id
Relationships:
products
Product
Attributes:
id
productGroupId
Releationships:
productGroup
Due to the limit of the server, I can't use incremental sync. When I sync my data, (for example) I have to delete all ProductGroup objects, get response from server, then create new ones(and some old ones again).
The problem is, if I have a productA belongs to productGroupB, usually I can do productA.productGroup, but after I delete productGroupB and create another one with the same content, the relationship is lost.
So I am wandering is there any way to manage relationships by FKs, like the Entity Framework in .NET, so I can still find the object on the other end of the relationship after re-create.
You lose the relationship when you delete the ProductGroup objects because Core Data isn't SQL. In the case of relationships, Core Data cares nothing about the attributes of the object on the other side of the relationship, it just targets a specific object. You can have an arbitrary number of objects with the exact same attributes but different relationships and the objects will be completely distinct. A Core Data relationship is not an SQL join or key but a persisted pointer-like reference to a specific managed object. Delete the object and the pointer has to go as well.
To accomplish what you want, you could use a fetched property which would fetch on the Product.id attribute dynamically. However, that is a fairly clumsy way of doing things. You shouldn't have to resort to a fetched property in this instance.
I think you need to rethink your design. I have never seen a case where you had to delete an every instance of an entity/class just to add or remove objects. As a practical matter, you can't actually do that in one go. Instead you have to fetch the objects and then delete them one-by-one. You might has well check each object for if it needs to be deleted or updated while you are at it.
It sounds like you receive a great glob of SQL format data from the server and you think you have to build the object graph from scratch. You really shouldn't have to. You have to parse the data to create new ProductGroup objects anyway, so you should use the results of that parsing to alter the existing ProductGroup objects.
In pseudo-code it would look like:
Add a "synced" flag to ProductGroup entity in the data model
Set "synced" of every ProductGroup object to "false"
Extract data for a ProductGroup from server glob
Using data fetch for an existing ProductGroup object
If extracted data matches and existing ProductGroup object
update existing ProductGroup object
set synced of ProductGroup object to true
else
create new ProductGroup object with data
set synced of new ProductGroup object to true
Delete all ProductGroup objects where synced == false
The important thing to remember here is that you are dealing with objects and not tables, columns, rows or joins. People skilled in SQL often assume that Core Data is just an object wrapper around SQL. It is not. It is an object graph manager that may or may not use SQL far behind the scenes to persist (freeze dry) the object graph to disk.
You have to think in objects always. The intuitions you've developed for working with SQL are more likely to lead you astray than help you with Core Data.