MVVM在导入/使用语句中的关注点分离

时间:2015-05-29 22:09:02

标签: c# vb.net linq entity-framework mvvm

我一直在努力坚持MVVM模式,但后来我遇到了一些我不确定的事情。

让我构建场景。我有一个实体框架项目和我的主要项目。我为处理所有LINQ语句的ef对象构建了一个Manager类。正如预期的那样,我需要将EF模型导入此管理器类。但是,当我从ViewModel传递来自管理器的对象时,我还必须将EF模型导入ViewModel。

看起来这实际上违背了MVVM模式。有什么东西我错过了吗?我阅读的大部分内容基本上都表明你遵循MVVM直到它更容易打破它。

所以这是经理类

Imports ProjectManagerDbConnect
Public Class PMDB_BillingPeriods_Manager
Public Function GetLast12Periods() As List(Of BillingPeriod)
    Using ds As New PMEntities
        Dim qry = From p In ds.BillingPeriods
                  Order By p.BillPeriod Descending
                  Select p

        Dim billingPeriodList As List(Of BillingPeriod) = New List(Of BillingPeriod)(qry.Take(12).ToList())
        Return billingPeriodList
    End Using


End Function
End Class

ViewModel Class

Imports System.Collections.ObjectModel
Imports ProjectManagerDbConnect
Public Class BillingPeriodViewModel
Inherits CommonBase

Public Sub New()
    Try
        loadLast12Period()
    Catch ex As Exception

    End Try
End Sub

Private mPeriods As ObservableCollection(Of BillingPeriod)
Public Property Periods() As ObservableCollection(Of BillingPeriod)
    Get
        Return mPeriods
    End Get
    Set(ByVal value As ObservableCollection(Of BillingPeriod))
        mPeriods = value
        RaisePropertyChanged("Periods")
    End Set
End Property

Private Sub loadLast12Period()
    Dim mgr As New PMDB_BillingPeriods_Manager
    Periods = New ObservableCollection(Of BillingPeriod)(mgr.GetLast12Periods)
End Sub
End Class

0 个答案:

没有答案