Skip to content

Parent/Children self referenced entity with SQLite #201

Answered by MoonStorm
jfmary-storkcom asked this question in Q&A
Discussion options

You must be logged in to vote

I think that this section of the wiki would apply to your situation: https://github.com/MoonStorm/FastCrud/wiki/JOINs#referencing-the-same-entity-multiple-times

So for this entity registration:

[Table("location")]
class Location
{
  [Key]
  [Column("id")]
  public long Id { get; set; }

  [ForeignKey(nameof(ParentLocation))]
  [Column("parent")]
  public long? ParentId { get; set; }

  public Location ParentLocation { get; set; }

  [InverseProperty(nameof(Location.ParentLocation))]
  public IEnumerable<Location> ChildrenLocations { get; set; }
}

then this call should work:

var locations = dataConnection.Find<Location>(statement => statement
  .WithAlias("locations")
  .Include<Location>…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jfmary-storkcom
Comment options

You must be logged in to vote
1 reply
@jfmary-storkcom
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants