I've been playing with Dapper-Contrib for a bit and having problem retrieving an object using .Get so that I can maintain change tracking for the object.
My Interface:
Imports Dapper.Contrib.Extensions
Public Interface ICountry
<Key>
Property CountryGUID As Guid
Property Country As String
End Interface
The Class:
Imports Dapper.Contrib.Extensions
<Table("Country")>
Public Class Country
Implements ICountry
<Key>
Public Property CountryGUID As Guid Implements ICountry.CountryGUID
Public Property Country As String Implements ICountry.Country
End Class
My function:
Public Function Find(countryId As Guid) As ICountry
Dim country As ICountry
Using conn = New SqlConnection(ConnectionString)
conn.Open()
country = conn.Get(Of ICountry)(countryId)
conn.Close()
End Using
Return country
End Function
And I got an error saying Invalid object name 'Countrys' when calling the above function.
The problem seems to be caused by Dapper sqlmapperextensions automatically adds āsā to tablename and that can be solved by defining TableAttribute. However, TableAttribute is supported for classes only but not interfaces.
Please note that I have to call .Get
with an interface to have tracking functionality.