sql - 如何为客户特定数据使用通用变量

标签 sql .net vb.net entity-framework orm

我创建了一个包含常用变量的通用 dll。我有用户定义的占位符字段,因此我们可以保存客户特定的数据。此 dll 将用于特定于客户端的应用程序。

如何将这些通用变量映射到相关的 sql 表字段,以便我们可以操作自定义数据库?我想避免编写自定义查询。

像 dapper 这样的 ORM 在这里有用吗?

编辑:根据 danihp 的回应,我已经开始研究 Entity Framework 工作。看起来很有希望。我推断使用 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

最佳答案

您正在寻找entity framework .您可以轻松地将您的类映射到表。它们之间只有 2 个相关的类。将这些类映射到具有 Entity Framework 的表非常容易。然后,您将避免编写查询,只需 LINQ 表达式和通过具有导航属性的表进行导航。

Entity Framework (EF) is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write.



通常创建一个数据访问层。 "Entity Framework is Microsoft’s recommended data access technology for new applications "

您的代码看起来很容易被 EF 处理,但如果不是,您可以编写新类来轻松地保留您的自定义类。

您可以在 Entity Framework Fluent API with VB.NET 上通过示例 EF VB.NET 代码学习

关于sql - 如何为客户特定数据使用通用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44190050/

相关文章:

mysql - 有没有办法检查表中的新行是否与其他表中的条目一致? [SQL]

SQL 选择其中一列值在另一条件列中通用的行

c# - C# 事件创建的 VB 等效项

sql - 使用 MAX() 而不分组

java - 提交响应后无法转发 Servlet 错误

c# - Entity Framework + SQL Server Compact + WPF/WinForms = 缓慢的 UI?

c# - 使用 BouncyCaSTLe 加密私钥

c# - 使用列表 IndexOf 时未设置 Combobox SelectedIndex

vb.net - 如何在安装项目时将文件保存/安装到用户计算机的 C 驱动器中?

css - 单图像 VB.Net 应用程序中的图像 Sprite