Skip to content

Make a better distinction foreign key fulfillment and automatically adding inserts #22

@carl-berg

Description

@carl-berg

Background

Currently this setting is controlled via Dude.EnableAutomaticForeignKeys(...), however quite a few users have misunderstood what the options here means. There are two concepts at play here:

  1. Using previous inserts to set FK columns when inserting rows. The default behavior here is to always fill a dependency if it is available and the column value has not been set manually (to null for example). This is enabled by setting Dude.EnableAutomaticForeignKeys() with no parameters.

  2. Analysing FK dependencies of tables being inserted to and automatically adding extra inserts where needed, depending on dependency traversal strategy. This is enabled by setting Dude.EnableAutomaticForeignKeys(c => c.AddMissingForeignKeys = true). It's also possible to set a dependency traversal strategy like this to change from the default strategy or plugging in your own strategy:

Dude.EnableAutomaticForeignKeys(c =>
{ 
    c.AddMissingForeignKeys = true;
    c.DependencyTraversalStrategy = DependencyTraversalStrategy.SkipNullableForeignKeys;
}

The problem

The confusion however seem to be that the dependency traversal strategy affects whether foreign keys are filled in scenario 1, which is not what it is for. I think this is a failure of the library api, it's not clear enough what the difference is and i think it could be changed to make the distinction clearer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions