I've created a generic dll that holds commonly used variables. I have user defined fields that are place holders so we can hold customer specific data. This dll will be used in client specific apps.
How can I map these generic variables to the relevant sql table fields so that we can manipulate the custom database? I want to avoid writing custom queries.
Would an ORM like dapper be useful here?
Edit: Per danihp's reponse, I've started looking into Entity frame work. It looks promising. I'm inferring that using Fluent API I can make this dll portable into unique apps and pass a db object (instead of my class?) to do business logic.
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
And:
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
1 Answers
Answers 1
You are looking for entity framework. You can easily map your classes to tables. You have just 2 classes related between them. Is so easy to map this classes to tables with entity framework. Then you will avoid to write queries, just LINQ expression and navigation though tables with navigation properties.
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.
It is usual to create a Data Access Layer. "Entity Framework is Microsoft’s recommended data access technology for new applications"
Your code looks easy to be handled by EF, but, if not, you can write new classes to easily persist your custom classes.
You can learn by example EF VB.NET code at Entity Framework Fluent API with VB.NET
0 comments:
Post a Comment