question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Table relation with itself

See original GitHub issue

I have a table that joined with itself, like this :

public class Stuff
{  
    public int Id { get; set; }
    public string? Title{ get; set; } 
    public int ChildId { get; set; }
                                                             
    public virtual ICollection<Stuff> Stuffs{ get; set; }
}

But when I use Scaffold, It makes two classes like this :

public class Stuff
{  
    public stringId { get; set; }
    public string? Title{ get; set; } 
    public string ChildId { get; set; }
                                                             
    public virtual ICollection<Stuff> Stuffs{ get; set; }
}

public class Stuff1
{  
    public int Id { get; set; }
    public string? Title{ get; set; } 
    public int ChildId { get; set; }
                                                             
    public virtual ICollection<Stuff> Stuffs{ get; set; }
}

How can I fix this issue?

Provide technical details

  • EF Core version in use: EF Core 7
  • Is Handlebars used: yes
  • Is T4 used: yes
  • Is .dacpac used: yes
  • EF Core Power Tools version: 2.5.1277
  • Database engine: SQL Server
  • Visual Studio version: Visual Studio 2022

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Feb 1, 2023

Ping?

1reaction
ErikEJcommented, Jan 31, 2023

Please share your CREATE TABLE script

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL table: create 1-to-1 relationship with itself?
I want to create a 1-to-1 relationship on a table with itself. I have a table MenuItem , but I want the items...
Read more >
Types of Relationships :: Chapter 10. Table Relationships
A table bears a self-referencing relationship (also known as a recursive relationship) to itself when a given record in the table is related...
Read more >
Relationships in SQL - Complete Guide With Examples
A self-referencing relationship (also known as a recursive relationship) in a database occurs when a column in a table relates to another column ......
Read more >
Self-relations - Prisma
A relation field can also reference its own model, in this case the relation is called a self-relation. Self-relations can be of any...
Read more >
Defining a table's relationship ... to itself
I have a table consisting of the Event Ids and a 'Related' Id, which is of course simply the Id of another event....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found