0

I'm new to EF, so I need your support. Every time I actualize my EF Model from database (Database First), EF creates the method "OnModelCreating":

Namespace FDB.Model

Partial Public Class FDBEntities
    Inherits DbContext

    Public Sub New()
        MyBase.New("name=FDBEntities")
    End Sub

    Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
        Throw New UnintentionalCodeFirstException()
    End Sub

In this method, the "UnintentionalCodeFirstException" will be thrown. How can I prevent EF from creating this exception? Everytime I change this method, EF of course will override it when the model is actualized. I already created a second class "Partial Public FDBEntities" with a "On ModelCreating"-method in it, but that won't work:

Partial Public Class FDBEntities
    Inherits DbContext

    Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
        MyBase.OnModelCreating(modelBuilder)
    End Sub
End Class

After actualizing the EDM, this method will be underlined red, because there already exists a method with identical signature.

FYI: Initially I indeed use Code First, but I completely removed the Datalayer (folders and files) and create a new one with Database First, so I think, this cannot be the reason for this exception.

  • http://stackoverflow.com/a/5942978/2319909 – Sam Makin Dec 14 '15 at 15:17
  • Possible duplicate of [Model First with DbContext, Fails to initialize new DataBase](http://stackoverflow.com/questions/5940616/model-first-with-dbcontext-fails-to-initialize-new-database) – Lukas Kabrt Dec 14 '15 at 18:30

0 Answers0