2017-05-25 36 views
7

我已經創建了一個通用的dll來存放常用的變量。我有用戶定義的字段是佔位符,因此我們可以保存客戶特定的數據。這個DLL將用於客戶端特定的應用程序。如何將通用變量用於客戶特定數據

如何將這些通用變量映射到相關的sql表字段,以便我們可以操作自定義數據庫?我想避免編寫自定義查詢。

這樣的ORM就像小巧玲瓏會有用嗎?

編輯:根據danihp的反應,我已經開始關注實體框架的工作。看起來很有希望。我推斷使用Fluent API我可以將這個dll移植到獨特的應用程序中,並傳遞一個db對象(而不是我的類)來執行業務邏輯。

Public Class Runs 
    Private _RunMailPeices As Dictionary(Of String, MailPiece) = New Dictionary(Of String, MailPiece) 
    Private _run As Integer  
    Private MailDate As DateTime 
    Public Property RunMailPeices As Dictionary(Of String, MailPiece) 
     Get 
      RunMailPeices = _RunMailPeices 
     End Get 
     Set(value As Dictionary(Of String, MailPiece)) 
      _RunMailPeices = value 
     End Set 
    End Property 

    Public Property run As Integer 
     Get 
      run = _run 
     End Get 
     Set(value As Integer) 
      _run = value 
     End Set 
    End Property 
End Class 

和:

Public Class MailPiece 

    Private _address1 As String = String.Empty 
    Private _address2 As String = String.Empty 
    Private _string1 As String = String.Empty 
    Private _string2 As String = String.Empty 
    Public Property Address1 As String 
     Get 
      Address1 = _address1 
     End Get 
     Set(value As String) 
      _address1 = value 
     End Set 
    End Property 

    Public Property Address2 As String 
     Get 
      Address2 = _address2 
     End Get 
     Set(value As String) 
      _address2 = value 
     End Set 
    End Property 
    Public Property String1 As String 
     Get 
      String1 = _string1 
     End Get 
     Set(value As String) 
      _string1 = value 
     End Set 
    End Property 

    Public Property String2 As String 
     Get 
      String2 = _string2 
     End Get 
     Set(value As String) 
      _string2 = value 
     End Set 
    End Property 
End Class 
+2

學習我猜你不平均淨仿製藥,因爲沒有什麼在與他們無關。看起來它會導致數據進出數據庫I/O的DLL的數據比保存的數據更多。 – Plutonix

+0

這就是我想弄明白的。如果我能這樣做,我可以利用很多其他內部DLL。 – DavidTheDev

回答

5

您正在尋找entity framework。您可以輕鬆將您的課程映射到表格。他們之間只有兩門相關的課程。將這些類映射到具有實體框架的表很容易。然後,您將避免編寫查詢,只是LINQ表達式和導航通過具有導航屬性的表。

實體框架(EF)是一種對象關係映射器,它使.NET開發人員能夠使用特定於域的對象處理關係數據。它消除了開發人員通常需要編寫的大部分數據訪問代碼的需求。

通常創建一個數據訪問層。 Entity Framework is Microsoft’s recommended data access technology for new applications

您的代碼看起來很容易被EF處理,但是,如果沒有,您可以編寫新類以輕鬆地保留您的自定義類。

可以通過例如EF VB.NET代碼在Entity Framework Fluent API with VB.NET

相關問題