将两个表合并为一个实体框架? (SQLite的)

时间:2016-06-25 01:27:30

标签: vb.net entity-framework sqlite uwp-xaml

我正在使用EntityFramework.SQLite库并且在我的生活中无法弄清楚如何将两个表组合成一个临时表以便在xaml代码中显示。

这里是我想要组合的两个表的代码,这是我现在使用的所有内容,除了我的临时表类ClassList(这是业务/数据逻辑DLL库的一部分)之外:

Partial Public Class CategoryList
        Public Sub New()
            Me.CategoryInfo = New CategoryReference
            'Me.CategoryCode = New HashSet(Of CategoryCodes)
            Me.CategoryCodes = New CategoryCodes

        End Sub


        Public Property MyId As Integer

        <Key, ForeignKey("CodeID")>
        <Required>
        Public Property CodeID As Integer

        <Key, ForeignKey("CategoryID")>
        Public CategoryID As Integer

        'Public Property CategoryCode As ICollection(Of CategoryCodes)
        Public Property CategoryInfo As CategoryReference
        ' Public Property CategoryInfo As ICollection(Of CategoryReference)
        Public Property CategoryCodes As CategoryCodes
    End Class

    <Table("CategoryCodes")>
    Public Class CategoryCodes 'category shortnames/codes 
        <MaxLength(100)>
        <Required>
        Public Property CategoryCode As String
            Get
                Return _CategoryCode
            End Get
            Set(value As String)
                _CategoryCode = value
            End Set
        End Property
        Private _CategoryCode As String

        '<NotNull>
        ' <PrimaryKey>
        '<Unique(Name:="UQ__CategoryCodes__0000000000000081_CategoryCodes", Order:=0)>

        <Key>
        <Required>
        Public Property CodeID As Integer
            Get
                Return CategoryCode
            End Get
            Set(value As Integer)
                _CodeID = value
            End Set
        End Property
        Private _CodeID As Integer
    End Class
    <Table("CategoryReference")>
    Partial Public Class CategoryReference 'table design for category data

        <MaxLength(100)>
        Public Property CategoryName As String
            Get
                Return _CategoryName
            End Get
            Set(value As String)
                _CategoryName = value
            End Set
        End Property
        Private _CategoryName As String
        <MaxLength(100)>
        Public Property CategoryDescription As String
            Get
                Return _CategoryDescription
            End Get
            Set(value As String)
                _CategoryDescription = value
            End Set
        End Property
        Private _CategoryDescription As String

        '<Unique(Name:="UQ__CatagoryReference__000000000000005F_CatagoryReference", Order:=0)>
        <ForeignKey("CodeID")>
        <Required>
        Public Property CodeID As Integer
            Get
                Return _CodeID
            End Get
            Set(value As Integer)
                _CodeID = value
            End Set
        End Property
        Private _CodeID As Integer

        '<Unique(Name:="UQ__CatagoryReference__000000000000005A_CatagoryReference", Order:=0)>
        <Key>
        <Required>
        Public Property CategoryID As Integer
            Get
                Return _CategoryID
            End Get
            Set(value As Integer)
                _CategoryID = value
            End Set
        End Property
        Private _CategoryID As Integer

    End Class

它可能看起来很长但是表格非常简单,并且get / set块使它看起来很长(如果她/他希望的话,vb.net编辑器可以将它们变成简单的属性)。我可能正在使用CategoryList类错误,但我在主应用程序代码中的xaml数据源中使用它(我在dll库中有业务逻辑/数据处理):

  Private Property ViewModel As List(Of UIELLUWP.DataAccess.CategoryList)
    Dim categories As New UIELLUWP.DataAccess.SQLiteDb

        ViewModel = categories.Categories.ToList

使用当前代码收到的错误: 我收到一个表&#34; CategoryList&#34;运行上面的代码时不存在。

1 个答案:

答案 0 :(得分:0)

我的解决方案我发现这个问题是添加asnotracking因为正在进行跟踪。