CodeFirst OnModelCreating isn't fired

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Zero-G.
Posts: 391
Joined: Sat 09 Dec 2006 12:20

CodeFirst OnModelCreating isn't fired

Post by Zero-G. » Fri 20 Nov 2015 10:28

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.

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: CodeFirst OnModelCreating isn't fired

Post by Shalex » Fri 20 Nov 2015 13:11

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).

Zero-G.
Posts: 391
Joined: Sat 09 Dec 2006 12:20

Re: CodeFirst OnModelCreating isn't fired

Post by Zero-G. » Fri 20 Nov 2015 13:32

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

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: CodeFirst OnModelCreating isn't fired

Post by Shalex » Fri 20 Nov 2015 13:52

Please send us a small test project so that we can reproduce the issue in our environment.

Zero-G.
Posts: 391
Joined: Sat 09 Dec 2006 12:20

Re: CodeFirst OnModelCreating isn't fired

Post by Zero-G. » Fri 20 Nov 2015 14:16

I sent you an email
THX

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: CodeFirst OnModelCreating isn't fired

Post by Shalex » Mon 23 Nov 2015 12:13

We have answered you by email.

Post Reply