Quantcast
Channel: EntityFramework Reverse POCO Code First Generator
Viewing all articles
Browse latest Browse all 1642

New Post: add hasoptional relationship which doesn't exist in DB

$
0
0
Hi Jeff,

You do indeed seem to be missing a FK in your database. I looks like one was manually added to the EDMX, but was never created within the database.

The simple answer is to create a SQL patch, which adds the missing FK in the database. Then simply save your database.tt file to reverse engineer it. However you said you can't do this, so I'm wondering if you are using migrations, and no longer need to reverse engineer the database anymore.

Anyway, in order for you to fix this you need to edit the column.ConfigFk field.
Something like:
    UpdateColumn = (Column column, Table table) => 
    {
        if (table.NameHumanCase == "EntryLog" && column.NameHumanCase == "LogEntryId")
        {
            column.ConfigFk.Add("HasOptional(a => a.ContactedLogEntryDetail).WithRequiredDependent(b => b.LogEntryId)");
        }
        
        // Perform Enum property type replacement
        var enumDefinition = EnumsDefinitions.FirstOrDefault(e =>
            (e.Schema.ToLowerInvariant() == table.Schema.ToLowerInvariant()) &&
            (e.Table == table.Name || e.Table == table.NameHumanCase) &&
            (e.Column == column.Name || e.Column == column.NameHumanCase));

        if (enumDefinition != null)
            column.PropertyType = enumDefinition.EnumType;
        
        return column;
    };
I'm guessing the correct ConfigFk entry you need, but I'm sure you could set the right value.

Viewing all articles
Browse latest Browse all 1642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>