若要创建实体,请将实体控件从 Visual Studio“工具箱”添加到业务数据连接 (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
相关内容