共用方式為


將實體新增至模型

若要建立實體,請將 Visual Studio 工具箱中的實體控制項新增至 Business Data Connectivity (BDC) 設計工具。

將實體新增至模型

  1. 建立 BDC 專案,或開啟現有的 BDC 專案。 如需詳細資訊,請參閱建立商務資料連線模型

  2. 在 [工具箱] 中,從 BusinessDataCatalog 群組中,將實體控制項新增至設計工具。

    新的實體會出現在設計工具上。 Visual Studio 會將 <Entity> 元素新增至專案中 BDC 模型檔案的 XML。 如需 Entity 元素屬性的詳細資訊,請參閱 Entity

  3. 在設計工具中,開啟實體的捷徑功能表,選擇 [新增],然後選擇 [識別碼]

    新的識別碼會出現在實體上。

    注意

    您可以在 [屬性] 視窗中變更實體的名稱和識別碼。

  4. 定義類別中實體的欄位。 您可以將新類別新增至專案,或使用其他工具建立的現有類別,例如物件關聯式設計工具 (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; }
    
    }