foreign-keys

How do I create a primary key using two foreign keys in Entity Framework 5 code first?

我的未来我决定 提交于 2019-12-06 01:31:53
I have an entity where the primary key consists of two foreign keys to two other tables. I have the configuration working with the following but the table is generated with two FK references. The table: domain.Entity1 MorePK (PK, FK, int, not null) Entity2_Id (PK, FK, int, not null) Entity3_Id (PK, FK, int, not null) OtherData (varchar, null) Entity2_Id1 (FK, int, null) Entity3_Id1 (FK, int, null) is generated from: public Entity1 { public int MorePK { get; set; } public int Entity2_Id { get; set; } public int Entity3_Id { get; set; } public string OtherData { get; set; } public virtual

Multiple Foreign keys to a single table and single key pointing to more than one table

妖精的绣舞 提交于 2019-12-06 00:20:29
I need some suggestions from the database design experts here. I have around six foreign keys into a single table (defect) which all point to primary key in user table. It is like: defect (.....,assigned_to,created_by,updated_by,closed_by...) If I want to get information about the defect I can make six joins. Do we have any better way to do it? Another one is I have a states table which can store one of the user-defined set of values. I have defect table and task table and I want both of these tables to share the common state table (New, In Progress etc.). So I created: task (.....,state_id

Mysql errno 150 trying to create table with foreign key references

不羁岁月 提交于 2019-12-05 23:41:17
I'm trying to create a table in mysql with a foreign key reference, like this: In database A: CREATE TABLE replication ( id varchar(255) NOT NULL PRIMARY KEY, uid varchar(255) NOT NULL, value int(11) NOT NULL, FOREIGN KEY (uid) REFERENCES databaseB.users(username) ); In database B i have a table named users like this: +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | id | varchar(255) | NO | | NULL | | | username | varchar(255) | NO | PRI | NULL | | +-------------

Why does EF Code First [InverseProperty] attribute fail to work when used with [ForeignKey] attribute?

喜夏-厌秋 提交于 2019-12-05 22:46:21
Using: EF 4.3.1, Visual Studio 2010, SQL CE 4.0 My understanding is that when declaring Foreign Keys with DataAnnotation in EF, it can be done either of the following ways: Option 1- [ForeignKey("Player1Home")] public long? HPlayer1Id { get; set; } public virtual Player Player1Home { get; set; } Option 2- public long? HPlayer1Id { get; set; } [ForeignKey("HPlayer1Id")] public virtual Player Player1Home { get; set; } Problem: When the InverseProperty DataAnnotation gets used with Option 2 an extra column gets generated in the database (Player1Home_Id) in addition to HPlayer1Id. [Table("Matches"

Rails updating multiple models on a single form

回眸只為那壹抹淺笑 提交于 2019-12-05 21:56:24
Im writing a form which uses formtastic to manage the BusinessUnit model, however when creating a new BusinessUnit it also has to create a number of other record types. The associations between the models are as below: class BusinessUnit < ActiveRecord::Base has_many :business_unit_sites has_many :locations class BusinessUnitSite < ActiveRecord::Base belongs_to :site belongs_to :business_unit class Site < ActiveRecord::Base has_many :locations has_many :business_unit_sites class Location < ActiveRecord::Base belongs_to :business_unit belongs_to :site When a BusinessUnit is created, a Site must

Hibernate foreign key with a part of composite primary key

 ̄綄美尐妖づ 提交于 2019-12-05 21:17:59
问题 I have to work with Hibernate and I am not very sure how to solve this problem, I have 2 tables with a 1..n relationship like this: ------- TABLE_A ------- col_b (pk) col_c (pk) [other fields] ------- TABLE_B ------- col_a (pk) col_b (pk) (fk TABLE_A.col_b) col_c (fk TABLE_A.col_c) [other fields] How can I manage this with Hibernate? I do not have any idea how to declare a foreign key that would contain a part of primary key. My database schema is generated from the Hibernate model. 回答1: I

Change primary key value in Oracle

大憨熊 提交于 2019-12-05 20:52:10
Is there a way to change the value of a primary key which is referenced by another table as foreign key? An easier alternative is to insert a new row and delete the old one. (Update any referencing rows in other tables before you do the delete) There isn't an in-built UPDATE CASCADE if that's what you're after. You'd need to do something like disable any FK constraints; run UPDATE statements; re-enable the constraints. Note that updating Primary Keys is (usually always) a bad idea. You will need to disable the foreign key constraints before changing the primary key values, and then re-enable

Double Foreign Key in Django?

倖福魔咒の 提交于 2019-12-05 20:49:06
Is there anyway to model double foreign keys in Django? For instance if I had tables: audio, overlay, html and the table: timeline_item which has a field id, and a field category which specifies audio, overlay, or html... Does anyone know how I would go about modeling this in Django? or if it's even possible? Sounds like a polymorphic association. Maybe you can solve your problem with Django's generic relations using the ContentTypes framework. Foreign key is referential constraint between TWO tables so you really can't have one column referencing to 3 columns on 3 different tables. see: http:

Implementing foreign key type relationships in XSD schema

痞子三分冷 提交于 2019-12-05 20:29:49
I'm trying to wrap my head around xml schemas and one thing I'm trying to figure out is how to do relational type schemas where on element refers to another, possibly in another schema altogether. I've looked at the xsd:key and xsd:keyref and it seems like the sort of thing I'm interested in, but I'm not sure. Initially I just set attributes with the type xs:ID abd xs:IDREF, which obviously doesn't necessarily refer to a specific element as far as I could tell. Basically, I have several different xml files where elements refer to other elements either in the same file or other files. It looks

EF4: Get the linked column names from NavigationProperty of an EDMX

久未见 提交于 2019-12-05 19:11:50
问题 I am generating POCOs (lets say they are subclasses of MyEntityObject ) by using a T4 template from an EDMX file. I have 3 entities, e.g.: MyTable1 (PrimaryKey: MyTable1ID) MyTable2 (PrimaryKey: MyTable2ID) MyTable3 (PrimaryKey: MyTable3ID) These entities have the following relations: MyTable1.MyTable1ID <=> MyTable2.MyTable1ID (MyTable1ID is the foreign key to MyTable1) MyTable2.MyTable2ID <=> MyTable3.MyTable2ID (MyTable2ID is the foreign key to MyTable2) Or in another view: MyTable1 <=