I have the following model
public class PageConfig : Base
{
// Properties Etc..
public ICollection ScrollerImages { get; set; }
}
Per http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx:
"...you can use Fluent API to configure a One-to-Many relationship using Student entity classes as shown below."
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//one-to-many
modelBuilder.Entity()
.HasRequired(s => s.Standard)
.WithMany(s => s.Students)
.HasForeignKey(s => s.StdId);
}
"...Use HasOptional method instead of HasRequired method to make foreign key column nullable."
So you'd be looking for something like this:
modelBuilder.Entity()
.HasOptional(x => x.PageConfig)
.WithMany(x => x.ScrollerImages)
.HasForeignKey(x => x.PageConfigId)