通过发送

时间:2018-03-07 13:14:22

标签: vb.net entity-framework

我设法通过将表名作为字符串发送来从实体框架获取数据,如下所示

Public Class EFORMv1(Of t As New)

Dim dx As New EF_ORMv1.MyEntity

Function SelectByKey(Table$,Field$,Value As Object) As IEnumerable(Of t)
        Dim s = "SELECT * FROM " + Table + " WHERE " + Field + " = @p1"
        Dim r = dx.Database.SqlQuery(Of t)(s, New SqlParameter("@p1",Value))       
        Return r
End Function
End Class

我正在使用它

    Dim x As New EFORMv1(Of EF_ORMv1.CONTACT)
    Dim y = x.SelectByKey("CONTACT","NUM",1000).ToList
    Me.dataGridView1.DataSource = y

我正在搜索的不是将表名作为字符串作为参数发送,而是因为我在[New EFORMv1(EF_ORMv1.CONTACT)]中发送类型所以我想在SelectByKey()函数中使用它

这可能吗?

0 个答案:

没有答案