Use case: I would like to call a top level (parent) DTO that returns nested children DTO objects.
Example entities:
entity Person {
firstName String
lastName String
}
entity Dog {
petName String
}
relationship OneToMany {
Person{dog} to Dog{person required}
}
The generated PersonDTO does not include the DogDTO. I would like it to return the following:
{
"id": 1,
"firstName": "John",
"lastName": "Doe",
"dogs":
[
{
"id": 1
"petName": "Fido"
},
{
"id": 2
"petName": "Spot"
}
]
}
Thank you
Related
I want to take the raw JSON body from an HTTP post and write it directly into my CosmosDB.
Let's say the data looks like this:
{
"id": "123456",
"storeName": "City Bar and Grille",
"invoiceTotal": 65
}
However, the documentsOut.AddAsync command uses a format like this:
wait documentsOut.AddAsync(new
{
// create a random ID
id = System.Guid.NewGuid().ToString(),
body = sourceJson
});
And then I end up with a document that looks like this:
{
"id": "0e99d3ab-1956-4c0a-8ec1-99de5c987555",
"body": {
"id": "123456",
"storeName": "City Bar and Grille",
"invoiceTotal": 65
}
}
What I really want is to end up with this:
{
"id": "123456",
"storeName": "City Bar and Grille",
"invoiceTotal": 65
}
I'd like to drop the id = System.Guid.NewGuid().ToString() completely (which should not be hard).
How can I pass the raw JSON through without needing to add it to some parent node (such as body)?
Just to formalize my comment as an answer: You're specifically creating the body property of the Cosmos DB document you're creating:
wait documentsOut.AddAsync(new
{
// create a random ID
id = System.Guid.NewGuid().ToString(),
body = sourceJson
});
At the same time, you're ignoring the incoming ID. Since you wanted to preserve that ID, You can copy the ID over (as long as it remains unique within the partition) instead of generating a new GUID, and also grab individual properties from sourceJson to avoid the nested body element:
wait documentsOut.AddAsync(new
{
id = sourceJson.id,
storeName = sourceJson.storeName,
invoiceTotal = sourceJson.invoiceTotal
});
Using a similar example as shared by you in the question.
We can create a Model class with properties which want to store in database.
public class StoreDetails : TableEntity
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("storeName")]
public string StoreName { get; set; }
[JsonProperty("invoiceTotal")]
public string InvoiceTotal { get; set; }
}
Then can create object of model and pass that object to AddAsync()method. As shown in below screenshot.
var item = new StoreDetails
{
Id = Guid.NewGuid().ToString(),
StoreName = data.StoreName,
InvoiceTotal = data.InvoiceTotal
};
await storeDetailOut.AddAsync(item);
and when we triggered post API, got response as shown below.
As finally we can see the same record is stored in CosmosDB.
Given a simple Foo entity, which in turn contains a collection of Bar objects in mongodb
problem occurs only if a column is both an array and an embedded object.
#Entity()
export class Foo {
#ObjectIdColumn()
public id: ObjectID;
#Column()
public simple: string;
#Column(type => Bar)
public collection: Bar[];
}
export class Bar {
#Column()
value: boolean;
}
repository.create transforms the raw value
{
"simple": "string",
"collection": [
{ "value": true },
{ "value": false }
]
}
into simply
{ "simple": "string" }
I just took this from https://github.com/typeorm/typeorm/issues/2342 but same thing is happening on my end
Apparently, this is a bug in typeorm. As a workaround, you can set the collection manually until the issue is solved:
async createFoo(createFooDto) {
const newFoo = await this.repository.create(createFooDto);
// TODO: Remove when https://github.com/typeorm/typeorm/issues/1980 is solved
newFoo.collection = createFooDto.collection;
this.repository.save(newFoo);
}
If this is a regression (it used to work) you can try to downgrade typeorm until it is fixed.
I am new in the cucumber world and i just want to describe an aggregation for the context of my scenario. I have a model and a DataTransferObject like the one below and i want to write an REST Api which returns a JSON.
public class Product {
int id;
String name;
double basePrice;
ProductCategory category;
}
public class ProductCategory {
int id;
String name;
List<Customization> possibleCustomizationsForCategory;
}
public class Customization {
int id;
String characteristic;
double additionalPrice;
}
public class ProductDTO {
int productId;
String productName;
double basePrice;
Size size;
int productCategoryId;
String productCategoryName;
List<Integer> possibleCustomizationIds;
}
I want to write something like this:
Given the system has persisted the following products
When a client requests GET /products
Then he will receive a JSON like the following:
"""
[
{
"productId": 1,
"productName": "Kaffee",
"basePrice": 2.00,
"size": "SMALL",
"productCategoryId": 1,
"productCategoryName": "Hot Drinks",
"possibleCustomizationIds": [1,2,3,4,5,6]
},
{
"productId": 2,
"productName": "Kaffee",
"basePrice": 3.0,
"size": "MEDIUM",
"productCategoryId": 1,
"productCategoryName": "Hot Drinks",
"possibleCustomizationIds": [1,2,3,4,5,6]
}
{
"productId": 3,
"productName": "Cookie",
"basePrice": 1.0,
"size": "SMALL",
"productCategoryId": 1,
"productCategoryName": "Biscuite",
"possibleCustomizationIds": [8,9]
}
]
"""
But how can I write the Given part and describe the Object in a way that it will be clear that there are three different classes with aggregations?
I would keep Gherkin in a more business level language that describes the problem you are trying to solve.
I would then have the step definitions describe the solution to the problem.
Therefore, your gherkin could be:
Given the following products are in stock
| Product |
| Small Kaffee |
| Medium Kaffee |
| Small Cookie |
When I get a list of stock
Then I the three products should be shown as in stock
And I should be able to view the details about them
I have assumed this is a stock control situation. This Scenario could then be ran against a database, web api, or the GUI and should still be true, just will a different solution in place.. i.e. using different step definitions.
https://launchpad.graphql.com/9qvqz3v5r
Here is my graphQL example
If i passed userId:2 as static
{
user(userId:2){
firstName
lastName
}
}
I will get output as below
{
"data": {
"user": {
"firstName": "Joe",
"lastName": "spin"
}
}
}
I need same output using dynamic query variable
query getUserNameData($userId: User){
user(userId:$userId){
firstName
lastName
}
}
query variables
{
"userId" : 2
}
But i am getter error as :
Variable \"$userId\" cannot be non-input type \"User
http://prntscr.com/h2ojor
Can anyone help me?
http://prntscr.com/h2oop9
You have to specify datatype with ! this symbol to get the variables
query getUserNameData($userId: Int!) {
user(userId: $userId) {
firstName
lastName
}
}
Given this request DTO
public class CreateRecordRequest {
public Dictionary<string, object> Record { get; set; }
}
when I call the service passing this JSON
{
"Record": {
"File": {
"name": "DSC_3493_4_5.jpg",
"extension": ".jpg",
"size": 596002,
"rawFile": {}
},
"Notes": "",
"Type": ""
}
}
File has the deserialized value "{". Since ServiceStack has no way of knowing which object File maps to, I'm curious why it doesn't deserialize it as a dictionary ("{" is inexplicable). What is the easiest way to customize deserialization of a single value like this? I'm working with Kendo's upload control and this is the JSON it submits.
Because it's an object the Serializer doesn't know what type to dehydrate this into, you can force it to use a Dictionary<string,string> with:
JsConfig.ConvertObjectTypesIntoStringDictionary = true;