Skip to content

feat(schema): Doc for UniDirectionalOneToManyWithOneDbSet#26

Merged
kilfour merged 3 commits intoThreeStrikesRelab:mainfrom
kilfour:feature/doc-for-UniDirectionalOneToManyWithOneDbSet
Aug 12, 2025
Merged

feat(schema): Doc for UniDirectionalOneToManyWithOneDbSet#26
kilfour merged 3 commits intoThreeStrikesRelab:mainfrom
kilfour:feature/doc-for-UniDirectionalOneToManyWithOneDbSet

Conversation

@kilfour
Copy link
Contributor

@kilfour kilfour commented Aug 12, 2025

Moved File to own namespace.
Removed Property Name as it's redundant.
Removed sqlite test as there is no (apart from ddl dialect) noticable difference. Tried to put live code samples in the doc.
Fixes #24.

Generated Markdown Included Below:

Uni Directional One To Many With One Db Set

Because the entity used in the DbSet has a collection of another entity type, the latter are mapped as well.
EF infers and includes related entities in the schema even when only one side is explicitly registered in the DbContext.

When using the following simple model of one Blog containing many Posts:

public class Blog
{
    public int Id { get; set; }
}
public class Post
{
    public int Id { get; set; }
    public Blog Blog { get; set; } = default!;
}

And then adding a DbSet<Blog> to the DbContext EF generates the following ddl for Sql Server:

Blog:

    [
        "CREATE TABLE [Blog] (",
        "    [Id] int NOT NULL IDENTITY,",
        "    CONSTRAINT [PK_Blog] PRIMARY KEY ([Id])",
        ");"
    ];

Post:

    [
        "CREATE TABLE [Posts] (",
        "    [Id] int NOT NULL IDENTITY,",
        "    [BlogId] int NOT NULL,",
        "    CONSTRAINT [PK_Posts] PRIMARY KEY ([Id]),",
        "    CONSTRAINT [FK_Posts_Blog_BlogId] FOREIGN KEY ([BlogId]) REFERENCES [Blog] ([Id]) ON DELETE CASCADE",
        ");"
    ];

Index:

 "CREATE INDEX [IX_Posts_BlogId] ON [Posts] ([BlogId]);";

Note: No other mappings were added.

Moved File to own namespace.
Removed Property Name as it's redundant.
Removed sqlite test as there is no (apart from ddl dialect) noticable difference.
Tried to put live code samples in the doc.
Fixes #24.
@kilfour kilfour added the documentation Improvements or additions to documentation label Aug 12, 2025
@kilfour kilfour merged commit e9282ee into ThreeStrikesRelab:main Aug 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add some more explanation to UniDirectionalOneToManyWithOneDbSet

3 participants