Add property to association in Entity Framework 5 - many-to-many

I had a pure junction table (to represent a many-to-many relationship) in my database. That is, a table with only two columns, each of them being a foreign-key, and them together composing the primary-key.
EF hid that complexity from me by not mapping this table to an entity, as expected; it was mapped as an Association.
Then I added a new column to this junction table in my database, and went on to Update Model From Database in the EDMX. But the table remained as an Association, not turning into an Entity with 3 properties.
What am I missing?

The thing is you need to delete the association first. Go to Model Browser > Your Model > Associations, find and delete the association. Then you can update the model and the table will show up as an entity.

Related

Abstract Class from UML to ER diagram. Possible ? How?

I have the below UML class diagram with Abstract Class, and sub-Classes that extends from it. and i want to make an ER diagram using this class diagram.
My question is how can i represent the Abstract class in ER diagram ? as a Table ? or should i just ignore it ?
Thank you.
There are basically three choices to translate generalization into a database model
1. One table per concrete class
Create tables Admin, Teacher and Student. Each of these table contain columns for all of the attributes and relations of User
Pro
All fields of a concrete subclass are in the same table, so no join needed to get all Student data
Easy data validation constraints (such as mandatory fields for Student)
Con
All fields of User are duplicated in each subclass table
Foreign keys to User have to be split into three FK fields. One for Admin, one for Teacher and one for Student.
2. On table for whole generalization set
In this case you just have one table call User that contains all fields of User + all fields of all sub-classes of User
Pro
All fields are in the same table, so no join needed to get all User data
No splitting of FK's to User
Con
There are a bunch of fields that are never used. All fields specific for Student and Teacher are never filled in for Admins and vice versa
Data validation such as mandatory fields for a concrete class such as Student become rather complex as it is no longer a simple Not Null constraint.
3. One table per concrete class, and one for the superclass
In this case you create tables for each of the concrete sub-classes and you create a table for the class User. Each of the concrete sub-class tables has a mandatory FK to User
Pro
Most normalized schema: No repeated fields for the attributes of user, and no unused fields.
No splitting of FK's to User
Easy data validation constraints (such as mandatory fields for Student)
Con
You have to query two tables if you want all data of a Student
Complex validation rules to make sure each User record has exactly one Admin, Teacher or Student record.
Which one of these options you choose depends on a number of things such as the number of sub-classes, the number of attributes in either subclass or superclass, the number of FK's to the superclass, and probably a few other things I didn't think about.

Can a Core Data Relationship Have Attributes

I'm porting a MySQL database to Core Data for a Mac OS app. I have two many to many tables in my database. In addition to containing the foreign keys, there are a few data columns. Is it possible to add attributes to a many to many relationship in Core Data? It doesn't look like it to me. My fallback is to replicate the linkage table in Core Data. Are there any problems doing this?
An example:
A record has one or more artists performing on it.
An artist performs on zero or more records.
The linkage table row contains a foreign key for the record, a foreign key for the artist, the instruments the player performed with, and a notes column that adds additional information such has which track the artist performed on.
You are correct: relationships themselves cannot have attributes. And you are on the right track in modelling the linking table as an intermediate entity. This approach is alluded to in the CoreData Programming Guide section on "Modelling a relationship based on its semantics". In their case, they model a (reflexive) many-many relationship from Person to Person using an intermediate FriendsInfo entity with a ranking attribute.
In your example, you might have a Record entity, an Artist entity, and an intermediate Appearance entity. The Appearance entity would have attributes for Instruments and Notes, and (to-one) relationships to Record and Artist (each with a to-many inverse).
The slight downside is that you have to create the Appearance object in order to link a Record object and an Artist object, rather than just adding them to the relevant relationship. You will also have to watch for uniqueness of the combination of Record/Artist, if that's important to you: by default there could be many Appearances for the same Record and Artist.

Making MySQL tables

I'm currently working on a project, the admin of the application must be able to add/edit these information.
Class(className)
Teacher(teacherName,teacherInfo,teacherPicture,teacherEmail)
Practice(practiceName,practiceDate,practiceDescription,practiceDocs)
I tried making 3 tables of which the class would be the relational table containing the keys of teacher and practice, but that way I can't add only the subject without teachers and practices or add a Teacher and then afterwards assign him a class, or remove him from a class. So my question is how would I go about doing this or if you could point me to some good read for this problem.
If I understood it right, you have a practices table, a teachers table and a classes table, with relation fields put directly on those tables.
For you to be able to create teachers, classes and practices individually, you must take that relationship fields out and put the relations into separate tables.
So, instead of having, for example, a classes table with a teacher field, have a classes table without any field related to the teacher and another separate table classes_teachers where you'd have a unique identifier for the association, the id of the teacher and the id of the class.
The type of relationship your current schema provides is called a 1 by n relationship.
The kind of relationship you need is a n by n relationship.

Entity type not created for table with composite key

I'm using VS 2010, Entity Framework 4.3 and MySql.Data.Entity v6.3.5 to work with a MySQL DB with a couple dozen tables. I use the ADO.NET DbContext Generator.
Everything works well enough other than two tables don't get Entities created for them. Both have a similar structure in that they have a composite key composed of foreign keys to other tables. So, one is a region_flavor table that maps the (ice cream) flavors assigned to a particular sales region. It looks like so
region_flavor
-------------
RegionId INT(10) PK NN
Flavor VARCHAR(64) PK NN
RegionId is a FK to the regions table and Flavor is a FK to the ice_cream table.
There's another table with essentially the same situation.
When I do an "Update from Database", I see that there is, in the Model Browser, the table region_flavor listed under my IceCreamModel.Store\Tables / Views folder. But under my IceCreamModel\Entity Types folder there's no Entity Type.
I don't receive any .edmx errors when I do the update from the DB.
Perhaps I'm missing something here. Ideas?
I can post more info if that's helpful.
It is normal behavior. This is junction table used to model many-to-many relation in database. If it doesn't contain any additional column EF doesn't need to map it to entity because many-to-many relation is modeled directly and translated to table rows internally by EF.

JPA Entities - MySQL tables Mapping

Database tables:
Tutor( {PK}tutorId, name )
Module( {PK}moduleId, name, {FK}tutorId )
Relationship Tutor -> Module (OneToMany)
Questions:
If you create the domain model
classes with JPA annotations, the
corresponding database tables are
auto-created with the same columns as the annotated fields of the class?
Do you create the database first
and then the JPA classes with the
same fields as the database table
columns?
How do you model foreign key constraints with JPA
(1) and (2) are depended on your situation. you can create domain model class first and it will generate table and columns which are the similar to the fields. In addition, you can establish a database first (it is easy to design and have better view of the whole database.), then map the tables to your domain class.
about (3) you can try this link