Sdílet prostřednictvím


How to: Add an Entity to a Model

To create an entity, drag an entity from the Visual Studio Toolbox onto the Business Data Connectivity (BDC) designer.

To add an entity to the model

  1. Create a BDC project, or open an existing BDC project. For more information, see Creating a Business Data Connectivity Model.

  2. In the Toolbox, from the BusinessDataCatalog group, drag an Entity to the designer.

    The new entity appears on the designer. Visual Studio adds an <Entity> element to the XML of the BDC model file in your project. For more information about the attributes of an Entity element, see Entity.

  3. On the designer, right-click the entity, click Add, and then click Identifier.

    A new identifier appears on the entity.

    Poznámka

    You can change the name of the entity and the identifier in the Properties window.

  4. Define the fields of the entity in a class. You can either add a new class to the project or use an existing class created by using other tools such as the Object Relational Designer (O/R Designer). The following example shows an entity class named Contact.

    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
    
        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; }
    
        }
    

See Also

Tasks

How to: Add a Creator Method

How to: Add a Deleter Method

How to: Add an Updater Method

How to: Add a Finder Method

How to: Add a Specific Finder Method