0

I really need some help with this. I added a new table from my database to my .NET model and I created manually the entity class and the reference to access it but at runtime this error occurs... Can you help me out?

This code is the one that tries to run it:

Protected Sub ObtieneIdioma()
    Try
        Dim strHostName As String = System.Net.Dns.GetHostName()
        Dim ip As String
        ip = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
        Dim ip_array() As String = ip.Split(".")
        Dim ip_bigint As Int64 = Convert.ToInt64(ip_array(3))
        ip_bigint = ip_bigint + Convert.ToInt64(ip_array(2)) * 256
        ip_bigint = ip_bigint + Convert.ToInt64(ip_array(1)) * 65536
        ip_bigint = ip_bigint + Convert.ToInt64(ip_array(0)) * 16777216
        Dim Context = New segProdBDEntitiesPT()
        Dim ds = Context.dbip_lookup.Where(Function(x) x.Ip_Start <= ip_bigint AndAlso x.Ip_End >= ip_bigint).Single

        --- Bunch of code to determine language ---

    Catch ex As Exception
        'Error en el servicio
        Response.Cookies("Idioma").Value = "ENG"
        Response.Redirect("~/Welcome.aspx", False)
    End Try
End Sub

Here is my context file:

Partial Public Class segProdBDEntitiesPT
Inherits DbContext

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

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

--- Some other entities ---
Public Property dbip_lookup() As DbSet(Of dbip_lookup)

--- Some other Functions ---

End Class

Here is my entities file:

Imports System
Imports System.Collections.Generic

--- Other partial classes for other entities ---
Partial Public Class dbip_lookup
    Public Property Addr_Type As String
    Public Property Ip_Start As Int64
    Public Property Ip_End As Int64
    Public Property Country As String
End Class

I did all of this manually when I added the table dbip_lookup to my model and I do not know what I am missing

Lastly, here is the error thrown:

System.InvalidOperationException detected.
HResult=-2146233079
Message=The entity type dbip_lookup is not part of the model for the current context.
Source=EntityFramework
StackTrace:
     en System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
     en System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
     en System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
     en System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
     en System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
     en Site.ObtieneIdioma() en C:\Users\Carlos Flores\Documents\My Dropbox\CSI\Departamento de Calidad\Interno\CSIGroup\Site.Master.vb:línea 684
InnerException:
Carlos Flores
  • 29
  • 2
  • 9
  • Possible duplicate of [The entity type is not part of the model for the current context](http://stackoverflow.com/questions/20688922/the-entity-type-type-is-not-part-of-the-model-for-the-current-context) – Drew Nov 06 '15 at 16:00

1 Answers1

0

See the SO answer here: The entity type <type> is not part of the model for the current context

Try adding something like this to OnModelCreating:

Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
    modelBuilder.Entity(Of dbip_lookup)().ToTable("dbip_lookup")
End Sub
Drew
  • 2,601
  • 6
  • 42
  • 65