VS 2010实体存储库错误

时间:2010-06-12 01:10:42

标签: vb.net repository entity

在我的项目中,我设置了它,以便DB中的所有表都具有属性“id”,然后我使用存储库模式从EntityBase类继承实体对象。然后我在dbml文件o / r设计器中将“id”属性的继承修饰符设置为“覆盖”

Public MustInherit Class EntityBase
    MustOverride Property id() As Integer
End Class

Public MustInherit Class RepositoryBase(Of T As EntityBase)
    Protected _Db As New DataClasses1DataContext

    Public Function GetById(ByVal Id As Integer) As T
        Return (From a In _Db.GetTable(Of T)() Where a.id = Id).SingleOrDefault
    End Function
End Class

Partial Public Class Entity1
    Inherits EntityBase

End Class

Public Class TestRepository
    Inherits RepositoryBase(Of Entity1)
End Class

Return (From a In _Db.GetTable(Of T)() Where a.id = Id).SingleOrDefault
然而,当我使用VS 2010使用4.0框架时,

会产生错误“类成员EntityBase.id未映射”但我从未收到过旧错误的错误。任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:2)

终于找到了我的问题的答案....不得不将a.id = id改为a.id.equals(id)