LINQ: I have 3 tables and I want to make 2 join tables - linq

I have three tables, Question, SubjectType and CoreValue.
Question table has many to many association to SubjectType table and CoreValue table.
I want to make 2 join tables: one between Question and SubjectType and one between Question and CoreValue.
How do I make sure that the Association tables with CoreValue FK and Question FK gets filled without inserting any values in Corevalue? CoreValue Table already have the values that is needed. I just need to be able to have FK on Question and Corevalue in same association table without inserting any data same goes to Question and SubjectType.
Thanks for advice!
Best Regards!

Just create the tables as pure join tables in the database.
EF will generate a model with navigation properties (Question - SubjectTypes, and so on). You probably want to remove the associations SubjectType.Questions and CoreValue.Questions.
See also this tutorial (the Class-Student part).

Related

OBIEE RPD: Snowflaked table not showing up as a fact table in the BMM layer

I am using the RPD tool to create a data model for a database which has 6 tables.
Dimensions : ProductFamily, ProductionLine,Company,CurrencyExchange
Facts: WorkOrderStats, WorkOrder
But, WorkOrder is not getting taken as a fact table in the BMM layer.
How do I make the WorkOrder as a fact table in the BMM layer?
Any input is sincerely appreciated.
Thank you
That's not how facts work in OA. Facts never join to facts. Ping me on slack. I created that exact RPD last Friday.
If you want to join your fact table to an other fact table you have to create an other alias for your fact, the new alias will act as a dimension. in your case create an alias for F_workorder name it Dim_workorder for exemple and join your F_workorderStat to this dimension and keep F_workorder and it's relations just remove the relation between F_workorderStat and F_workorder it's not going to work that way.

Table joins in BigQuery

Do you know if there's a way to join two tables by, for
example, using a foreign key constraint like in MySQL (I don't seem to
find anything about this) ? If not, is there a replacement ?
Thanks!
I interpret your question as below -
Is there a way to limit the values that can be used on the tableX to only the IDs that exist on the tableY? For example via using a foreign key constraint like in MySQL!
BigQuery does not provide any direct mechanism for this to happen.
But you can easily achieve this by yourself.
For example, assume you need to insert some data to tableX, but you want to make sure that only those rows will be inserted where id in that new data is in tableY
So, you can "enforce" this via below query
#standardSQL
SELECT n.*
FROM newData AS n
JOIN tableY AS y
ON n.id = y.id
... you can run this query with tableX as destination and ONLY needed rows will be inserted
Hope you got an idea
Also you can check existing related feature requests -
https://issuetracker.google.com/issues/35906045
https://issuetracker.google.com/issues/35906043
Since you asked two questions (Stack Overflow suggests asking 1 question per question), I'll answer one:
Also, do you know if there's a way to join two tables by, for example,
using a foreign key
In BigQuery you can join tables by any key - even by keys defined on the fly (this is pretty useful when you need to join two tables from different datasets that choose to encode identical values in different ways).
Why would you need a foreign key to do these joins?

Change 1:M relationship to M:M in an Oracle database

I have a question about how to change relationships between tales in an Oracle database while preserving existing data.
Let's say I want to represent People and Employers such that each person works for a single employer. I do this with a PERSON table and an EMPLOYER table with a 1:M relationship of EMPLOYER to PERSON. The PERSON table had columns ID, NAME, and EMPLOYER_ID, and the EMPLOYER table had columns ID, NAME, AND LOCATION.
If I wanted to update this schema so a PERSON can work for more than one EMPLOYER, I could add a PERSON_EMPLOYER table with columns for each ID.
Could anyone give some pointers on the most sensible way to do this and move my existing data in? I think I can add a join table, but I'm not sure how to populate it with existing employer:employer data. After that I guess I remove EMPLOYER_ID column from PERSON.
Should I just be backing up the database and doing this operation in a script?
Thank you so much.
Having a backup is always a good idea.
But in my opinion transferring data from one table to another it is quite reliable operation. You do not necessary make a script, just do it step by step and check changes.
Create a new PERSON_EMPLOYER table
Copy existing data to PERSON_EMPLOYER table.
COMMIT data changes.
Check data in PERSON_EMPLOYER table
Drop EMPLOYER_ID column from PERSON table. (No need to remove the column immediately, it can be done later when you will be sure that everything is fine with the your data.)
For transferring data from PERSON table to PERSON_EMPLOYER table you can use simple INSERT
INSERT INTO employer_person (employer_id, person_id)
SELECT employer_id, person_id FROM person;
Do not forget COMMIT this operation!

Link tables with extra column in Symfony 2 / Doctrine

In a database I have the tables User, Group and UsersInGroup and generate the entities from the database using the Symfony 2 console. The table UsersInGroup is not generated as an entity but is partly generated into User and Group. This would be perfect if UsersInGroup hat only two columns userId and groupId (together primarykey), in this case the table UsersInGroup also contains a third column Role. This field is can never be filled using the generated entities
How should I fill the Role column in the tabel UsersInGroup?
You have to declare your relation table manually and to map the relations.
You'll find an interesting discussion here:
Doctrine2: Best way to handle many-to-many with extra columns in reference table

DB project - improving performance with relationships

I have two tables, let's call them TableA and TableB. One record in TableA is related to one or more in TableB. But there's also one special record within them in TableB for each record from TableA (for example with lowest ID), and I want to have quick access to that special one. Data from both tables aren't deleted - it's a kind of history rarely cleared. How do that the best in terms of performance?
I thought of:
1) two-way relationship, but it will affect insert performance
2) design next table, with primary key as FK_TableA (for TableA record exactly one is "special") and second column FK_TableB and then create view
3) design next table, with primary key as FK_TableA, FK_TableB, make FK_TableA unique and then create view
I'm open for all other ideas :)
4) I'd consider an indexed view to hide the JOIN and row restriction
This is similar to your options 2 and 3 but the DB engine will maintain it for you. With a new table you'll either compromise data integrity or have to manage the data via triggers

Resources