gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:17:12 25 4
gpt4 key购买 nike

我创建了一个包含常用变量的通用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com