Relation in Mongodb Parse-server - mongodb

I have two questions on how to model a mongo database
1:
In 1: N, with mongodb, should I save the child entity's ID of the parent entity object, or the parent entity to save an Array with the child IDs?
In the Parse-Server I could not make the result return a list with the IDs in the parent table, I found the ID of the daughter easier and search the table for all the results that have the ID of the parent table
2:
I read about Many-to-many in Mongo, but in my db I did as SQL, I have a third table that stores the ID from the two tables.
That's right? Can it cause errors? Or performance problems?

Related

How to correctly add a list of objects to database, working with multiple tables?

My database looks like this: Database Diagram MSSMS
So everytime i'm adding a fish to the database, i want to add the fishes's continent, waterlagen and verbanden.
Tables Continenten, Waterlagen & Verbanden are already filled with objects from an array after creating the database.
Im using List Continenten; for example to store multiple continents.
So i tryed:
Vis nieuweVis = new Fish();
nieuweVis.Naam = "Molly";
foreach(Continent c in Continenten)
nieuweVis.Continenten.Add(c)
so in the table VisContinenten
i assume that EF will automaticly fill in the FishId and ContinentId wich are foreignkeys.
I want records in that table also to be unique so i add a unique key to both the columns in VisContinenten so that fish 1 on continent 1 won't appear twice in that table.
Error i get:
An error occurred while saving entities that do not expose foreign key
properties for their relationships
Additional information: Unable to update the EntitySet 'VisContinenten' because it has a DefiningQuery and no element exists in the element to support the current operation.
Help me pls :)
Thank you

EF 6 Remove entity connected to read only view

I have two entities: one based on normal DB table and another base on DB View. They are connected one to many, like this:
Entity City do not have store procedures mapped because for entity Country it is enough to have read only collection of Cities.
And cascade rule is not set.
But then I want to delete Country instance which have some Cities loaded I've received the following error:
Unable to update the EntitySet because it has a
DefiningQuery and no 'DeleteFunction' element exists in the
'ModificationFunctionMapping' element to support the current
operation.
Which forcing me to create dummy stored procedure on DB and use it as Delete function, but it is an ugly solution.
Is there any better solution?

How can I replicate core data model using a traditional relational database?

I have my app using core data with the data model below. However, I'm switching to a standard database with columns and rows. Can anyone help me with setting up this new database schema?
First of all you need to create tables for each of the Entities and their attributes (note I added "id" to each of the tables for relationships):
Routine (name, timestamp, id)
Exercise - this looks like a duplicate to me, so leaving one only here (muscleGroup, musclePicture, name, timeStamp, id)
Session (timeStamp, id)
Set (reps, timeStamp, unit, weight, id)
Now that you have tables that describe each of the entities, you need to create tables that will describe the relationships between these entities - as before table names are in capitals and their fields are in parenthesis:
RoutineExercises (routine_id, exercise_id)
SessionExercises (session_id, exercise_id)
ExerciseSets (exercise_id, set_id)
That's it! Now if you need to add an exercise to a routine, you simply:
Add an entry into Exercise table
Establish the relationship by adding a tuple into RoutineExercises table where routine_id is your routine ID and exercise_id is the ID of the newly created entry in the Exercise table
This will hold true for all the rest of the relationships.
NOTE: Your core data model has one-to-many and many-to-many relationships. If you want to specifically enforce that a relationship is one-to-many (e.g. Exercise can only have 1 routine), then you will need to make "exercise_id" as the index for the RoutineExercises table. If you want a many-to-many relationships to be allowed (i.e. each exercise is allowed to have multiple routines), then set the tuple of (routine_id, exercise_id) as the index.

adding entries to the "Relational" table in entity model? how do i do that?

so the story is very simple.
I have one table called Products and another Called categories. In addition, i have another table called ProductCategories that hold the relationship of catetories to their corresponding products (i.e, the table has two columns, ProductId, ColumnId).
For some reason, after adding all those table to my entity model, i don't have "Access" to it, hence i can do myentityModel.ProductCategories, so i could relational items between those two tables.
And yes, the ProductCategores table is added as "Association" to the entity model. i don't really understand that.
EDIT:
I do see that as part of creating new "Product" i can pass EntityCollection of "Category". So i do query from my entity model for a list of the matching categories that the user selected (on the webpage). so for example, i get (after query the model), an Objectset of "Category". However, i encountered two issues:
the 'AddObject' accept only EntityCollection, hence i need to re-create a set and then add all the objects from the ObjectSet to the entityCollection, in this process i need to detach it from the previous model and add it to the new collection. if not, i get an exception.
when i do the SaveChanges, i see that i get an exception that it was actually trying to Create new Category rather than adding new ProductCategory. again, am i missing something here?
Thanks.
This sounds like a Many-to-Many relationship. In your entity model, you don't need to declare the join table as a separate entity. Instead, you configure the relationship between the Products and the Categories as a Many-to-Many and add metadata about the join table. In Hibernate, you would have:
#ManyToMany(targetEntity=Categories.class, cascade={CascadeType.ALL}, fetch = FetchType.LAZY)
#JoinTable(name="tb_products_categories",
joinColumns=#JoinColumn(name="category_id"),
inverseJoinColumns=#JoinColumn(name="product_id")
)
#IndexColumn(name="join_id")
public List<Categories> getCategories() {
return categories;
}
When you query, the ORM layer takes care of determining SQL and traversing table joins.

Model a 1-to-many relationship with a single table in Entity Framework

Lets say I have 2 tables on my physical model, Receipt(ID, Location) and LineItem(ID, ReceiptID, ItemName) where a Receipt has multiple LineItems and ReceiptID is a Foreign Key to Receipt's ID.
I want to model these as a single table in my conceptual model, where I only see a table of LineItems with the Location included on each LineItem.
Every time I try to model this in the Entity Modeler, I get an error about how the Primary Key must be the same for every table being combined into the single conceptual entity.
Is this even possible to model using the entity framework?
Thanks!
No there is no way to model this directly. You must either create database view and map that view or import both entities and create QueryView in the model. In both cases resulting entity combining your two tables will become readonly and the only way to support CUD operations will be mapping stored procedures.