若要建立實體,請將 Visual Studio 工具箱中的實體控制項新增至 Business Data Connectivity (BDC) 設計工具。
將實體新增至模型
建立 BDC 專案,或開啟現有的 BDC 專案。 如需詳細資訊,請參閱建立商務資料連線模型。
在 [工具箱] 中,從 BusinessDataCatalog 群組中,將實體控制項新增至設計工具。
新的實體會出現在設計工具上。 Visual Studio 會將 <Entity>
元素新增至專案中 BDC 模型檔案的 XML。 如需 Entity 元素屬性的詳細資訊,請參閱 Entity。
在設計工具中,開啟實體的捷徑功能表,選擇 [新增],然後選擇 [識別碼]。
新的識別碼會出現在實體上。
注意
您可以在 [屬性] 視窗中變更實體的名稱和識別碼。
定義類別中實體的欄位。 您可以將新類別新增至專案,或使用其他工具建立的現有類別,例如物件關聯式設計工具 (O/R 設計工具)。 下列範例顯示名為 Contact 的實體類別。
public partial class Contact
{
public int ContactID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string Phone { get; set; }
public int EmailPromotion { get; set; }
public bool NameStyle { get; set; }
public string PasswordHash { get; set; }
public string PasswordSalt { get; set; }
}
Partial Public Class Contact
Private _ContactID As Integer
Public Property ContactID() As Integer
Get
Return _ContactID
End Get
Set(ByVal value As Integer)
_ContactID = value
End Set
End Property
Private _FirstName As String
Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
_FirstName = value
End Set
End Property
Private _LastName As String
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Private _EmailAddress As String
Public Property EmailAddress() As String
Get
Return _EmailAddress
End Get
Set(ByVal value As String)
_EmailAddress = value
End Set
End Property
Private _Phone As String
Public Property Phone() As String
Get
Return _Phone
End Get
Set(ByVal value As String)
_Phone = value
End Set
End Property
Private _EmailPromotion As Integer
Public Property EmailPromotion() As Integer
Get
Return _EmailPromotion
End Get
Set(ByVal value As Integer)
_EmailPromotion = value
End Set
End Property
Private _NameStyle As Boolean
Public Property NameStyle() As Boolean
Get
Return _NameStyle
End Get
Set(ByVal value As Boolean)
_NameStyle = value
End Set
End Property
Private _PasswordHash As String
Public Property PasswordHash() As String
Get
Return _PasswordHash
End Get
Set(ByVal value As String)
_PasswordHash = value
End Set
End Property
Private _PasswordSalt As String
Public Property PasswordSalt() As String
Get
Return _PasswordSalt
End Get
Set(ByVal value As String)
_PasswordSalt = value
End Set
End Property
End Class
相關內容