簡體   English   中英

如何指示Entity Framework對象正在實現接口?

[英]How to indicate that an Entity Framework object is implementing an interface?

好的,我必須開始說我正在使用Visual Basic。 問題是我有一個Entity Framework對象,並且想指出該對象實現了一個接口,例如:

Public Interface ICatalog
   Property created_at() As Date
   Property id() As Long
End Interface

這些屬性已在對象中就緒。 在c#中,我只是通過聲明該對象的部分類來完成此操作,並指出該對象實現了該接口,但是在basic不能正常工作的情況下,我認為這是因為用於表示某個屬性正在實現某個屬性的語言sintaxis接口,例如:

Public Property created_at() As Date Implements ICatalog.created_at

那么還有其他方法可以做到這一點嗎?

經過更多時間的谷歌搜索之后,我在另一個提示中找到了答案,但我沒有使用stackoverflow搜索引擎找到它,鏈接是:

局部類,LINQ,接口和VB.NET

僅作記錄,Visual Basic很爛

看一下這個例子。

Namespace MyAppDomain
    Public Interface IFoo
        Sub Bar()
    End Interface

    Public Interface IPerson
        Function Gender() As String
    End Interface

    Public Class MyFooPerson : Implements IFoo, IPerson
        Public Sub New()
        End Sub

        Public Sub Bar() Implements IFoo.Bar
        End Sub

        Public Function Gender() As String Implements IPerson.Gender
            Return Nothing
        End Function

    End Class
End Namespace

您會注意到MyFooPerson類實現了IFoo接口以及IPerson接口。 每個方法然后實現相應的Interface方法。

您的示例沒有說明包含Public Property created_at() As Date Implements ICatalog.created_at的類是否已Public Property created_at() As Date Implements ICatalog.created_at正在實現ICatalog接口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM