self-referencing-table

EF Core one-way self referencing entity binding

匆匆过客 提交于 2021-01-29 02:28:22
问题 I have set up a self referential entity using EF Core which looks like this: Entity public class DetailType { public int DetailTypeId { get; set; } public string Name { get; set; } public int? ParentTypeId { get; set; } public DetailType ParentType { get; set; } public IEnumerable<DetailType> ChildTypes { get; set; } } Binding modelBuilder.Entity<DetailType>() .ToTable("detailtype") .HasOne(x => x.ParentType) .WithMany(x => x.ChildTypes) .HasForeignKey(x => x.ParentTypeId); I am retrieving

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

安稳与你 提交于 2019-12-17 09:45:09
问题 Database Table: Image I tried this approach to map the category table to EF core: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Category>(entity => { entity .HasMany(e => e.Children) .WithOne(e => e.Parent) .HasForeignKey(e => e.ParentId); }); } Entity: [Table("Category"] public class Category : EntityBase { [DataType(DataType.Text), MaxLength(50)] public string Name { get; set; } public int? ParentId { get; set; } public int? Order { get; set; }

Represent a self reference table in a text tree

百般思念 提交于 2019-12-10 19:23:29
问题 I want to represent a self referencing table in a text tree (like TreeView but in text). I have been working on it and I did good so far. The problem is when I go few levels deep in the tree. So far The result is this: ┌──Main Group 1 │ ├──SubGroup 1.1 │ │ ├──SubGroup 1.1.1 │ │ ├──SubGroup 1.1.2 │ │ ├──SubGroup 1.1.3 │ │ └──SubGroup 1.1.4 │ │ ├──SubGroup 1.1.4.1 │ │ └──SubGroup 1.1.4.2 │ │ │ ├──Problem group 1 │ │ │ ├──Problem group 2 │ │ │ └──Problem group 3 │ │ │ │ └──Problem group 3.1 │ ├─

sorting Self-Referencing Relationship

人走茶凉 提交于 2019-12-08 03:09:58
问题 Assume the following model. Note the self-referencing relationship "parent". public class Category { public virtual long Id { get; set; } public virtual string Name { get; set; } public virtual Category Parent { get; set; } public virtual long? ParentId { get; set; } } My data are as follows: id | name | parentId 1--------tag 1 ----- null 2--------tag 2 ----- 1 3--------tag 3 ----- 1 4--------tag 4 ----- 2 5--------tag 5 ----- null 6--------tag 6 ----- null I want to write a query that data

How to create Hibernate Mapping for a self referencing table

早过忘川 提交于 2019-12-07 03:09:37
问题 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 manager is also an Employee, it would be in the same table. Hence every Employee row has a manager Id which is also an employee. How do we create Hibernate Mapping for this Employee Class? How would the Employee class look like? Does it have just a

d3.js Zoomable Sunburst visualization from self-referencing CSV input

主宰稳场 提交于 2019-12-06 13:58:35
问题 I'm a newbie at d3.js and need help to adapt Zoomable Sunburst to make it work with self-referencing CSV data. Sample lines from the input CSV: id,parentId,name,size ROOT,NULL,Root, RE,ROOT,General > Revenue Expenditure, RE11,RE,Main supervision recovery etc., RE11A109K,RE11,Shivjayanti celebrations and lighting,170000 RE11H108,RE11,Electicity for import tax naka,2550000 RE11J,RE11,Maintaince for main building, RE11J101A,RE11J,Electricity expenditure,11475000 RE11J101 C,RE11J,Power lift

How to create Hibernate Mapping for a self referencing table

北城余情 提交于 2019-12-05 08:39:10
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 manager is also an Employee, it would be in the same table. Hence every Employee row has a manager Id which is also an employee. How do we create Hibernate Mapping for this Employee Class? How would the Employee class look like? Does it have just a manager Id in it or it will contain another Employee Object as a member variable. Kindly help me with

d3.js Zoomable Sunburst visualization from self-referencing CSV input

∥☆過路亽.° 提交于 2019-12-04 18:45:31
I'm a newbie at d3.js and need help to adapt Zoomable Sunburst to make it work with self-referencing CSV data. Sample lines from the input CSV: id,parentId,name,size ROOT,NULL,Root, RE,ROOT,General > Revenue Expenditure, RE11,RE,Main supervision recovery etc., RE11A109K,RE11,Shivjayanti celebrations and lighting,170000 RE11H108,RE11,Electicity for import tax naka,2550000 RE11J,RE11,Maintaince for main building, RE11J101A,RE11J,Electricity expenditure,11475000 RE11J101 C,RE11J,Power lift,2125000 As you can see, there are variable levels of depth. At some places the data is coming at 3rd level,

How to efficiently load data from a self related table

匆匆过客 提交于 2019-11-30 13:27:59
问题 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 - PostId ChildPostId Title Post Content UserName ===================== I can retreive this kind of data using a recursive CTE. I am not sure this is the best approach. Questions What is the best way to retreive this data using SQL? Is there a better way to load this data using an ORM? If we go

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

╄→尐↘猪︶ㄣ 提交于 2019-11-27 21:40:48
Database Table: Image I tried this approach to map the category table to EF core: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Category>(entity => { entity .HasMany(e => e.Children) .WithOne(e => e.Parent) .HasForeignKey(e => e.ParentId); }); } Entity: [Table("Category"] public class Category : EntityBase { [DataType(DataType.Text), MaxLength(50)] public string Name { get; set; } public int? ParentId { get; set; } public int? Order { get; set; } [ForeignKey("ParentId")] public virtual Category Parent { get; set; } public virtual ICollection<Category>