This is a migrated thread and some comments may be shown as answers.

Foreign Key To script

0 Answers 37 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Henry
Top achievements
Rank 1
Henry asked on 13 Apr 2016, 07:00 AM

Hi

I have been all over the forums in trying to find a solution to why I can not get my foreign keys to be written to script.

I have done the following:

Did the Override CreateModel method code in my FluentModelMetadataSource class:

protected override MetadataContainer CreateModel(){
    MetadataContainer container = base.CreateModel();   
    container.DefaultMapping.NullForeignKey = true;
 return container;}

I setup my one to many Associations as per example:

productConfiguration.HasAssociation( p => p.Category ).WithOpposite( c => c.Products ).HasConstraint( ( p, c ) => p.CategoryId == c.Id );

And created my classes with same association as your examples of the Category and Product classes. Understanding that Product is the foreignKey table.

I saw a post, lost the link, that described using the MetaJoinTableAssociation that works with Many-To-Many as I can figure out. I treid going the more or less the same root, but MetaForeignKeyAssociation doesn't work the same way.

At the moment I am using CreateDDLScript() and CreateUpdateDDLScript(null). The script contains all my tables and Primary Keys, but foreign keys is for some reason not being included.

Is there something I am missing?

 

Tags
Data Access Free Edition
Asked by
Henry
Top achievements
Rank 1
Share this question
or