Questions tagged [self-referencing-table]

Refers to database tables with a column that is a foreign key to another column within the same table.

131 questions
13
votes
1 answer

Map category parent id self referencing table structure to EF Core entity

Database Table: I tried this approach to map the category table to EF core: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity .HasMany(e => e.Children) …
10
votes
1 answer

How to create Hibernate Mapping for a self referencing table

I was asked how I would create a hibernate mapping for a column in a table that refers to the primary key of the table. For example, an Employee table has EMP_ID as primary key and it also has MGR_ID column to know the manager of the employee. As a…
chandra
  • 129
  • 1
  • 1
  • 8
8
votes
3 answers

EF6 Self Referencing Table with multiple parent properties, single child collection

I have a table that references itself, but I am struggling with getting my desired mapping. I want to be able to define Children to be a collection of people that have a given person as Mother, Father, and/or Guardian. A Guardian may be the father…
7
votes
1 answer

ON DELETE SET NULL on self referencing relationship

I have the table with one primary key and one foreign key referencing the same table primary key. i.e there are parents and childs in the same table. In sql sever there are three options for the delete rule. But it is only possible to set "NO…
mattti
  • 121
  • 4
7
votes
1 answer

How to change the ordering of sql execution in hibernate

I am trying to model bidirectional parent-child design, with ordered children. When removing child (eg. child #2 of 3 children) from the parent, hibernate's generated sql led to unique constraint violation because "update" (sibling) is being…
YeenFei
  • 3,180
  • 18
  • 26
6
votes
1 answer

How to efficiently load data from a self related table

Consider the following requirement for building a forum App Parent Post - Child Post1 - Child Post1-1 - Child Post1-2 - Child Post1-2-1 - Child Post2 - Child Post - Child Post3 Table Structure tblPost -…
Perpetualcoder
  • 13,501
  • 9
  • 64
  • 99
5
votes
1 answer

Reverse self referencing foreign key in Django

Sorry if this is a stupid question, but I'm a bit of a Django newbie and can't find the answer. I have an Order model with a self-referencing field: source = models.ForeignKey( 'self', help_text = "[redacted]", verbose_name = "Source…
charredUtensil
  • 153
  • 1
  • 11
4
votes
2 answers

Self Referencing Table SQL query

I've table with four columns id, name, designation, manager_id. Table schema: CREATE TABLE "Employee_Information" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "designation" varchar, "manager_id" integer…
Aravind
  • 534
  • 1
  • 6
  • 18
4
votes
2 answers

Modeling Employee-Assistant(s) relationship with EF Code First

Here are the business requirements, in short: All employees need to be stored in a database Some employees have assistants, some do not Some employees have more than one assistant Assistants are employees, as well There is obviously a bit of a…
4
votes
3 answers

How to define a filter box out of the ng-table?

All I create a filter box in ng-table following the instrunctions of http://bazalt-cms.com/ng-table/example/4 my code is same as the example: create filter in html:
Zhao Leo
  • 101
  • 1
  • 3
3
votes
1 answer

Self referencing / parent-child relationship one-to-zero or one in Entity Framework Core

I want to create a referencing / parent-child relationship one-to-zero or one in Entity Framework Core. I mean that my entity could have a parent: public class MyEntity { public Guid Id { get; set; } public Guid? ParentEntityId { get; set;…
Simone
  • 2,304
  • 6
  • 30
  • 79
3
votes
1 answer

Entity Framework Core 3.0 - Creating a self-referencing many to many relationship

So here is my issue...what I am trying to create is a self-referencing many to many relationship. Basically here is my model. public class InformationSystem { public InformationSystem() { Systems = new HashSet(); …
3
votes
2 answers

SELECT inherit values from Parent (self-references)

I have 02 tables Rubrique and BulletinRubrique the table Rubrique contain the following columns : ID int not null, Name, varchar(max) not null, RubriqueA_ID int null, RubriqueB_ID int null with data for example…
3
votes
1 answer

How to implement an self referencing many to many relationship with Entity Framework Core 1.1?

I'm following this tutorial to implement my friendship system with EF Core 1.1 : http://www.codedodle.com/2014/12/social-network-friends-database.html Friendship.cs public class Friendship { public Guid ApplicationUserId { get; set; } public…
3
votes
2 answers

Entity Framework Core One-One Self Referencing Relationship fails

When building the migration I get the following error: Unable to determine the relationship represented by navigation property 'Location.NorthLocation' of type 'Location'. Either manually configure the relationship, or ignore this property from the…
1
2 3
8 9