将Dapper.Contrib CRUD方法与模型继承一起使用

时间:2017-04-19 13:44:49

标签: c# dapper-contrib

使用Dapper.Contrib CRUD方法可以使用继承的模型吗?

所以我有一个Persons表和一个Employees表以及以下匹配的实体。

nameof(ViewModel<>.Name)

我正在尝试执行以下操作:

Sub S43490204()
    Dim filePath As String
    Dim fso
    Dim oCollection As New Collection

    filePath = "lines.txt"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txtStream = fso.OpenTextFile(filePath, 1, False) '1 = ForReading

    On Error GoTo closeTarget

    Do While Not txtStream.AtEndOfStream
        oCollection.Add txtStream.ReadLine
    Loop

closeTarget:
    txtStream.Close

    'I'm not sure why you'd want an array instead of a collection
    Dim myArr() As String: myArr = GetStringArrayFromCollection(oCollection)

    For i = LBound(myArr) To UBound(myArr)
        Debug.Print " - " + myArr(i)
    Next i

End Sub

Function GetStringArrayFromCollection(oCollection As Collection) As String()
    Dim arr() As String
    Dim i As Integer

    ReDim arr(0 To oCollection.Count - 1)

    For i = 1 To oCollection.Count
        arr(i - 1) = oCollection(i)
    Next i

    GetStringArrayFromCollection = arr

End Function

但是我收到以下消息:

  

列名称无效&#39; FullName&#39;

在Person类中存在的每个列的第二个public class Person { public int Id { get; set; } public string FullName { get; set; } } public class Employee : Person { public int Id { get; set; } public string Dept { get; set; } } 上,因为它们不存在于Employees表中。

这是我的数据库架构。

int newid = (int)connection.Insert<Person>(emp);
connection.Insert<Employee>(emp);  // This line errors with missing columns

0 个答案:

没有答案