Тип объекта dbip_lookup не является частью модели для текущего контекста, когда я добавляю новую таблицу в существующую модель.

Мне действительно нужна помощь с этим. Я добавил новую таблицу из своей базы данных в свою модель .NET и вручную создал класс сущности и ссылку для доступа к ней, но во время выполнения возникает эта ошибка... Можете ли вы мне помочь?

Этот код пытается запустить его:

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

Вот мой файл контекста:

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

Вот мой файл сущностей:

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

Я сделал все это вручную, когда добавил таблицу dbip_lookup в свою модель, и я не знаю, что мне не хватает

Наконец, вот выброшенная ошибка:

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:

person Carlos Flores    schedule 06.11.2015    source источник
comment
Возможный дубликат тип сущности ‹type› не является частью модели для текущего контекста   -  person Drew    schedule 06.11.2015


Ответы (1)


См. ответ SO здесь: Тип сущности ‹type› не является частью модели для текущего контекста

Попробуйте добавить что-то вроде этого в OnModelCreating:

Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
    modelBuilder.Entity(Of dbip_lookup)().ToTable("dbip_lookup")
End Sub
person Drew    schedule 06.11.2015
comment
Возможно, мне нужно обновить строку подключения, но я не знаю, как это сделать. - person Carlos Flores; 06.11.2015
comment
В вашем файле web.config должна быть строка подключения с именем segProdBDEntitiesPT. - person Drew; 06.11.2015