Page 1 of 1

CodeFirst OnModelCreating isn't fired

Posted: Fri 20 Nov 2015 10:28
by Zero-G.
Hey
I use your latest EntityDeveloper Tool
I want to override the OnModelCreating method. Therefore I created a class with the following Code:

Code: Select all

Imports System.Data.Entity

Namespace Context
    Public Class CreateModel
        Inherits Entities
        Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
            modelBuilder.HasDefaultSchema("")
        End Sub

    End Class
End Namespace
Entites is the class generated by the DbContext template (for VB.NET)
I see within VS 2015 that OnModelCreating has 1 Reference - The reference goes toe the OnModelCreating Sub within the Entites class.
But it is never called. - As I understand it right, this Method should be called, when the Class is created!?

THX for tips.

Re: CodeFirst OnModelCreating isn't fired

Posted: Fri 20 Nov 2015 13:11
by Shalex
Please open your *.edml model and set the following properties:
1) Tools > Entity Developer > Model Explorer > Templates > DbContext
Fluent Mapping = True
Mapping Generation Strategy = UseOnModelCreatingMethod
2) select diagram surface (EntityContextModel)
Metadata Artifact Processing = Do Not Generate Mapping Files
Save the model to regenerate the code.

Does this help? If not, check if OnModelCreating is fired in the generated class (Entities).

Re: CodeFirst OnModelCreating isn't fired

Posted: Fri 20 Nov 2015 13:32
by Zero-G.
Hey
THX for your Reply, but it doesn't work
I also excluded the .msl, .ssdl and .csdl file from the Project, but still the onGenerated isn't fired up.
But maybe there is a much easier way to just Change the Schema Name!?

THX

Re: CodeFirst OnModelCreating isn't fired

Posted: Fri 20 Nov 2015 13:52
by Shalex
Please send us a small test project so that we can reproduce the issue in our environment.

Re: CodeFirst OnModelCreating isn't fired

Posted: Fri 20 Nov 2015 14:16
by Zero-G.
I sent you an email
THX

Re: CodeFirst OnModelCreating isn't fired

Posted: Mon 23 Nov 2015 12:13
by Shalex
We have answered you by email.