Creating an AssociationSetMapping for MySQL with the Entity Framework Designer? - mysql

I am trying to build an Entity Framework model for my database schema using EF4 and Visual Studio 2010. Since I am stuck using MySQL as our database (for now), I pretty quickly discovered that since MYISAM tables don't support foreign key constraints, the designer does not have any way to automatically create all the associations for you. It is easy enough to go through the model and build them all manually, but I ran into a problem trying to map a pure join table.
Normally if you are using SQL Server or some other database that supports Foreign Keys, the designer will create all the mappings for you and in the case of pure join tables will create an AssociationSetMapping such that the join table is entirely hidden in the model. Instead you end up with a Many to Many mapping between two two primary entities.
However I am at a loss as to how to create this kind of mapping manually? If I create a Many to Many association between my two entities, I end up with a regular Association, not an AssociationSetMapping. There does not appear to be a way to create one of these in the designer than I can figure out, and to tell it which join table is supposed to be used at the database level.
Am I missing something, and there is a way to do this?
If not, I suppose I have to hack the XML directly, but at this point it is not clear what I need to add to the XML files and where, in order to manually create the association set mapping?

Ok, I can answer this one myself. Once you create a many to many association with the designer, you DON'T set a referential constraint on it, but rather use the Mapping Details window to tell the association what table is the join table, and which keys map to which fields in the database. Simple enough once I figured it out :) But I could not find any good documentation on this.

Related

Same table in multple schemas

New to this, I am creating a database for an application. As the schema is becoming visually complex very rapidly, is it possible/feasable/recommended to have the same user_table in multiple schema?
For example, the blogging schema would have the user_table and the rest of the tables related to this activity. The shopping schema would again have the same user_table and the tables to manage the shopping activity. And so forth....
The objective would be to separata the plenty of tables in different schemas so to simplify the overall managements.
In another post, someone suggested creating a synonym in one the of schemas, referencing the other schema table. Is it the way to go or am I totally misrepresenting problem and solution?
Thank you for your time reading this.
A user table serves two diffent features, each in its own schema:
Sharing tables between schemas is not directly possible. There's a feature called federated tables, which however is not enabled by default and must be enabled at compile time of a MySQL server. So, it's rather not available for your task.
Instead you have only two options:
Use a single schema to avoid data duplication.
Use multiple schemas and maintain tables like the user table in each of them in parallel (by executing the same update queries on each of them).

Does IntelliJ has a function to visualize the relationship between two specific tables in a database?

I'm working with a big mySQL database in IntelliJ.
I'm trying to join two tables which aren't in a direct key-relation to each other. Hence I have to join over multiple tables.
Because I barley know the database scheme, I can't find out these tables in a appropriate time. I know that IntelliJ has a function which can visualize all tables with their relations within the database but does it also provide a function where I can find out all tables in between two specific tables?
You can get help from Intellij partially for your task, using the visualization feature as follows-
The relationship between tables are clearly shown.
For your question, you need to check the primary and foreign keys for each table which are easy to know as they are highlighted.
Traversing them you can find the relationship.

extending existing database - interfaces

I am working on extending the existing project which has been in production for couple of years and I need to extend a few existing entities, lets call them a,b,c,d.
When I now think about the designing of a database all the a,b,c,d should have some sort of inheritance, but changing the schema too much is impossible at this point.
Now all the a,b,c,d have their own primary keys but they all have to implement certain interfaces like - "bookmarkable", "taggable", "viewable" etc.
Would it make sense to keep creating tables like
a_saved, b_saved, c_saved, d_saved or a_tags, b_tags, c_tags etc to model the relation? But then again.. I would have to create THE SAME code to handle each of the scenarios where the only difference it's the table name!
I think better solution would be to create an new table - lets call it "object" and try to model some inheritance - for each entity create an entry in the "object" table and store that id in it's table and then create one relational table to map object_tag relation.
Does this sound like feasible solution or possibly error-prone and will bite me in the feature?
A similar solution to your second idea would be to create a single table that maps an extension by a combined (entity type, entity ID) key. See here for a sample schema and query: http://sqlfiddle.com/#!9/3c0235/1/0

Adding to MS Access relationship diagram programmatically

I have an application that ships to the customer with a JET database including a relationship diagram which more savvy users are invited to view to gain insight into the construction of the database.
I also have code in my application to update the database structure when new versions require new tables, new columns, or modified queries. I do this by pushing SQL through the ADO connection it works fine.
The problem is that if I add a new table with a constraint that relates it to an existing table (for instance, I add EmployeeHobbies with an FK relationship to an existing PK in Employees), while the table is constructed correctly the new relationship does not appear in the relationship diagram. Over time the diagram becomes progressively less complete.
Is there a programmatic method to force Access to update its relationship diagram from constraint information in the database or, failing that, is the relationship diagram stored in some hidden system object that I can update directly to reflect my changes?
Edit: I failed to make clear that my application is written in Delphi, not MS Access. Users who have a copy of MS Access can see the relationship diagram, others cannot.
I do not know if RunCommand will suit, but for what it's worth:
DoCmd.RunCommand acCmdRelationships
DoCmd.RunCommand acCmdShowAllRelationships
You may be able to leverage Stephen Lebans' SaveRelationshipView for this. His code saves properties for each item from the Relationships view to a table. Later the same layout view can be recreated from the table.
You could adjust your copy of the Relationships view to determine the values to include for a new row in the tblRelationshipViews table. Then let the users recreate their Relationships view based on the updated table information. Perhaps you could even automate to do it for them automatically.

Updatable views - SQL Server 2008

A question about updatable db views: I'm reading through some MSDN documentation on the subject, and I come across the following restriction:
Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
I just want to be sure I understand the restriction. I'd like to use views in a couple of my media review projects. The relational data is spread throughout tables, but a view seems to be the best way to be able to consolidate the data I need from multiple tables (some of which are linked via foreign keys) into a centralized location. Since the columns would come from a variety of tables, does this mean I can't run one blanket INSERT or UPDATE to persist changes in all the columns?
You can use an INSTEAD OF trigger on a view to keep your application only dealing with the view instead of the collection of base tables the view references.
Here is an example : Designing INSTEAD OF Triggers
Yes that's what it means. I see no advantage to updating through a view since you have to know what the base tables involved are anyway.