是否可以创建实体字典并在数据层中引用它

时间:2014-06-28 19:50:32

标签: vb.net entity-framework dictionary

我的数据库实际上是一个实体模型所基于的查找表。当我响应特定实体的OnPropertyChanged事件时,我想引用它。鉴于可能有数百个对此表的请求,我认为从该查找表创建字典并参考该字典会更有效。为此,我有一个mty实体的部分类,我添加了以下内容。

Imports System.Data.Entity

Partial Public Class FireTrackerEntities : Inherits DbContext

Private _defUnitsOfMeasurement As Dictionary(Of Int16, string)
Public Property DefUnitsOfMeasurement As Dictionary(Of Int16, string)
    Get
        Return _defUnitsOfMeasurement
    End Get
    Set(ByVal Value As Dictionary(Of Int16, string))
        _defUnitsOfMeasurement = Value
    End Set
End Property

Public Sub New()
    MyBase.New()
    CreateDictionaries()
End Sub

Private Sub CreateDictionaries()
    Dim ft As DbSet(Of FireTrackerModel.ExtinguisherType)
    For Each p In ft
        DefUnitsOfMeasurement.Add(p.ExtinguisherTypeId,p.DefaultUnitOfMeasurement)
    Next
End Sub

代码编译,但在我希望引用此词典的实体中,我无法看到它。那么这完全是错误的方法还是我错过了什么?

由于

1 个答案:

答案 0 :(得分:0)

您是否只是做这样的事情来创建Dictionary

myDbContext.SomeEntities.ToDictionary(Function(e) e.Id)