We're currently interfacing with an OData database, over HTTP.
I need to POST objects (i.e. create them). This works, but how can I get the identifier of the created object?
Comparing this to SQL, how could I get the last insert ID?
OData posts responses contain the object that was created. So, you should be able to parse the response and find out the key(ID). The $metadata document would tell you which properties are the keys.
Related
I'm using Entity Framework 6 and OData. I have a model A with several nav properties to other models, for example, model B. For a Get, I want to be able to call A, and Expand to B (I can do this successfully). The tricky bit is that now I want to be able to call Patch, and inside the body, include all the data for A as well as the nested data for B.
I know that EF does not accept data in virtuals, so I figured I could pull that data our in my application and null out those fields manually before saving with EF. That would be great.
However, the only way I can get OData to accept my subobject is by specifying that the type of the property B is a complex object, by adding this line to the model builder...
builder.ComplexType<B>();
I can then pass in nested data of this type on Patch, but now my Get doesn't work, because it says you can't expand to complex types, only navigational types.
So, it only works one way or the other. Any ideas on how I can accomplish something like this for both situations at the same time?
Thanks!
You can use the $ref to set up the link between entities.
For example:
POST ~/As to create a new A to As, from the response, you can get the location Id. So, you can get the key of new A
POST ~/Bs to create a new B to Bs, from the response, you can get the location Id. So, you can get the id (uri) of new B.
Then, you can use the $ref to create a link between the new A and the new B.
For the $ref, you can refer to the sample code here.
No matter what I try for EntityFilter, I can't seem to get any results. I believe that I must be mis-understanding what the EntityFilter does.
What entities is it filtering if I use it in a <DepositQueryRq>?
Copy/pasting from the documentation:
EntityFilter
An entity refers to a person on the QuickBooks Customer list, Vendor list, Employee list, or Other Names list. You can use an EntityQuery request to get information about all the entities that are set up in the QuickBooks file.
So an EntityFilter lets you filter deposits by entity. e.g. You can use it to get all deposits for a specific entity.
I have the problem that our backend uses an OData-"like"-Processor which has some special functions. It is oriented at OData_2.0
So the question will be:
What is the most OData like approach for this kind of the following requests
Our backend Data-Model has no single-attribute-keys. But it's recommended to be OData-Like if possible.
First: I need to delete several objects via one OData Request. My first idea is to use filters to define which objects should be deleted. But I', not sure if this is the right approach.
For Example: I want to delete all Items which have a price greater than 10.00
http://.../<oDataServiceX>/Item?$filter=ItemPrice gt 10.00
Second: When I want to delete an object which is not identifiable by one single key-attribute. How can I define that in the classical OData-Delete-Request-Syntax.
Is the following OData-like?
http://.../<oDataServiceX>/Item(1,54,2) //3 Attributes which define the key for the Item
Or should I do a filter again? (If filter is a proper way of doing this).
http://.../<oDataServiceX>/Item?$filter=keyAttr1 eq 1 and keyAttr2 eq 54 and keyAttr 3 eq 2
You can't delete multiple entries in a single OData query, you need first to retrieve their keys and then send multiple delete requests. There are two ways to improve this process:
Use OData batch to send all delete request in a single HTTP call.
Use some of libraries that can simulate deletion using filter (internally they will issue multiple requests but for the application it will look like a single call). One of such libraries is Simple.OData.Client.
Hope this helps.
Odata v4 supports the format DELETE /entity(key1='', key2='') and so on.
However, for oData v2, one option could be to use the request body to pass some data over. DELETE /entity, with data in the body.
The documentation states that the convention is to delete an entity by key. However, this was the approach followed when we had to delete by multiple keys for an odata v2 service. Also while implementing this using oData v2 libraries, we had to add a routing convention to support Delete without a key.
I have two tables each with one record(for testing and question purposes). These tables are Post and Comment. Post has a PFRelation called myComment (I know only one comment - lets call it a feature for now). If I query Post, how do I get the Post and Comment data back?
Can't find this anywhere using web search engines or Parse docs (not a complete answer at least).
Because Relation in Parse is just like its literal meaning, it does not contain any data. If you want to get the data back, you need to get that instance of Relation first. Then call query from that instance. After that, you just perform that query if you want to get all objects from this Relation. You can also add some constraints after getting the query from Relation.
If you use Pointer type, you can just get back the data by using includeKey:.
I'm making an "API" call for getting a list of "MyMusic" album. It returns array of music ids and those ids are linked with another table. So in order to get music details like name etc. I need to make separate "API" calls with id.
What is the recommended way to make "API" calls to fill my array with music details.
Depends on if the API can return multiple id's. Can you send a JSON-array to the API and get an array in return? If not, it looks like you have to send the id's one at a time.
If you don't for some reason NEED to use the REST api (which it seems you are doing now), then in your first query use includeKey on the field that contains the IDs. If this field is a Pointer to another table, this will make sure the full objects are returned in the first query instead of just the pointers.