foreign-key-relationship

How to create foreign key relationships with the Entity Framework?

I want to create a new row in my database on a table that has a couple of foreign key relationships and I haven't been able to get a handle on what order and what calls need to be made. This is what I have so far: db.Models.Order order = DB.Models.Order.CreateOrder( apple ); order.CustomerReference.Attach( ( from c in db.Customer where ...

How do I query for foreign keys that don't match their constraints?

SQL Server 2005. I'm adding Foreign Key constraints to the database of an application that allegedly didn't need them. Naturally, the data has become unreliable and there are orphaned entries in the foreign key field. Setup: Two tables, TableUser and TableOrder. TableUser has Primary Key 'UserID', and TableOrder has Foreign Key 'UserI...

How to create relationships in mySQL

In class, we are all 'studying' databases, and everyone is using Access. Bored with this, i am trying to do what the rest of the class is doing, but with raw SQL commands with mySQL instead of using Access. I have managed to create databases and tables, but now how do i make a relationship between two tables? If i have my two tables li...

How to Structure Table to Model Mutually Exclusive 1:n Relationships?

In the following table structure: Fruits ( fruit_id, fruitName ) Vegetables ( vegetable_id, vegetableName ) favoriteFoods ( food_id, foodName, type_id (References either a fruit or a vegetable) ) I realize that I could forgo using a foreign key constraint on the favoriteFoods table and then simply a...

LinqToEntities and Foreign Keys

I'm trying to use LinqToEntities and just noticed that there are no foreign key fields in the data model. That seems to cause some trouble when trying to add a record. Reading around I found that when adding a record you can do something like this (Product has a foreign key to the Categories table). Product myProduct = new Product(); ...

Rails: Scaffold to automatically do one-to-many relationship

Not sure if I'm reading this right, but it seems like Scaffold will not do a one-to-many relationship in its entirety. For instance, if I create messages with scaffold and then I want comments on those messages (one message -> many comments), I have to go through and change everything. For instance, I have to change this in the comment's...

EF insert related objects

Hi, I am using silverlight client with ado.net dataservices on entity framework. I have an Entity Contact and an Entity Address which is related with a foreign key relation ship... A contact can have 1 or more Adresses but a Address needs always at least 1 contact.. pretty basic... I have a Repository for my contacts and Address which...

How can I merge two mysql databases with identical schema?

I need to merge two two mysql databases with identical schema. I am looking for some tool that can read database meta-data (PK, FK) and automatically generate new PKs, updating all the FKs automatically. ...

One-to-One relationship in MS Access

I'm having trouble in creating a one-to-one relationship between two tables in MS Access - when I create the relationship, it defaults to "Many-to-one", and I don't see an option to change it. Is there a way to do this? ...

Uniqueness Constraints in MS Access

In a database I'm having to design for MS Access, I have a table called "Measurements", which stores certain measurement parameters (Measured Values, Std Deviation, etc.) - each row has an integer ID as its primary key. Other tables then link to this measurement table using foreign key relationships. Some tables contain two different "m...

Relationships with ASP.NET MVC

I usually use the Ruby on Rails framework but for this project I need to work with ASP.NET MVC and I'm confused. Basically I have 1 table : *Page = (id, name, category_id)* Category_id is actually a link to a page (a page can be linked to another page). I set up foreign keys and everything, the model is up and working. My question is...

How to use "one to many" relations in SubSonic

What are the ways to tell SubSonic about the relationship (only foreign keys? Or other methods too)? If I have (for example) a team object with related team members ** how do I access and update the team members from the team ** how do I update the team members? Does saving the team object saves the team members changes ** How do I a...

Problems with database relations with symfony framework - Cannot fetch TableMap for undefined table

Hello, Currently developing an application using the newest version of symfony, obtained through PEAR. This is my exact schema configuration propel: user: id: name: { type: varchar(255), required: true } level: { type: integer, required: true, default: 1 } created_at: post: id: title: { type: varchar(255)...

Creating an entity diagram of a database without any foreign keys

I need to create an entity diagram of a MSSQL 2005 database. Relationships are defined by using primary keys consistently, but there are no foreign keys anywhere. I tried Microsoft Visio's "Reverse Engineer" function, which of course failed due to the lack of foreign keys. Therefore, I need a diagram tool which doesn't solely rely on f...

In a bug/bug-status model, where would the foreign key reside?

I always get stuck on foreign keys so I have a question about where the foreign key should reside in a bug tracking system in which a bug has a single status at any given time while only a small number of statuses exist (Open, Under Investigation, Resolved, Pending Approval). So each status has many bugs associated with it. My assumption...

How to determine where to place the foreign key in this scenario?

If I have two tables - Logins and Users, as follows: Logins LoginIdNo UserIdNo HashedPassword Users UserIdNo LoginIdNo Username Each login "has a user" and each user "has a login" but which "belongs to" which? Is it simply a judgment call or is there a clearcut formula for determining where the foreign key should reside? ...

Configuring Entity Framework on a Database Undefined Foreign Key Relationships

For a variety of reasons the database that I'm working on (SQL Server 2005) doesn't have any relationships defined. Every table has a primary key. And most tables have at least one foreign key, however we've never configured the constraints. Can anyone tell me the steps that I should take to inform Entity Framework of the underlying rel...

Why can you not have a foreign key in a polymorphic association?

Why can you not have a foreign key in a polymorphic association, such as the one represented below as a Rails model? class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end class Article < ActiveRecord::Base has_many :comments, :as => :commentable end class Photo < ActiveRecord::Base has_many :commen...

Any example of a necessary nullable foreign key?

Customers customer_id Orders order_id customer_id fk If I have two tables and define a foreign key on customer_id in the Orders table, by allowing it to be null I am saying that I can have an order that does not have a customer associated with it. As such, the notion of a nullable foreign key seems at odds with the purpose of a for...

Entitry Framework Add To Intersection Table

Hi Every one, I have just started jumping into EF and cant seem to do something that seems simple. Here is my question and supporting info. Any help or suggestions will be greatly appropriated. I have a user table and a group table. Between these is a UserGroups Intersection table to allow a user to belong to any number of groups. T...