Created
February 12, 2010 16:53
-
-
Save actaneon/302742 to your computer and use it in GitHub Desktop.
Linq XML Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Data.Linq | |
Imports System.Data.Linq.Mapping | |
Imports System.Linq.Expressions | |
Imports System.Reflection | |
Imports System.IO | |
Public Class LinqMappingRepository(Of T As Class) | |
Private _db As DataContext | |
Public Sub New(ByVal connectionString As String) | |
Using mappingStream As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Namespace.Filename.xml") | |
Dim mapping As XmlMappingSource = XmlMappingSource.FromStream(mappingStream) | |
_db = New DataContext(connectionString, mapping) | |
End Using | |
End Sub | |
Public Function Find(ByVal expr As Expression(Of Func(Of T, Boolean))) As T | |
Return _db.GetTable(Of T).Where(expr) | |
End Function | |
End Class | |
'<?xml version="1.0" encoding="utf-8" ?> | |
'<Database Name="DB" xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007"> | |
' <Table Name=""> | |
' <Type Name="Namespace.Class"> | |
' <Column Name="PK" Member="ID" IsDbGenerated="true" IsPrimaryKey="true"/> | |
' <Column Name="DateStamp" Member="" IsVersion="true"/> | |
' <Column Name="Description" Member="Description"/> | |
' </Type> | |
' </Table> | |
'</Database> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment