Inherit from the Business Class Library Class Library class inherits from Business (EF)

In this lesson, you will learn how to implement business classes for your application using the Business Class Library. This library contains the most typical ready-to-use business classes. You will implement a custom Contact class by deriving from the Person class available in this library, and implement several additional properties. You will also learn the basics of automatic user interface construction based on data.

In this lesson, you will learn how to use Business class library for business class for the application. This library contains the most typical ready to use business class. You will implement a custom contact class, and implement multiple additional properties from this library available through the Person class is derived. You will also learn the basics of the user interface automatically constructed based on the data.

 

  • Typically, business classes should be implemented in a platform-independent module project, so that the same objects will be available in both WinForms and ASP.NET applications. To add a new class, right-click the Business Objects folder in the MySolution.Module project, and choose Add | Class... to invoke the Add New Item dialog. In this dialog, specify "Contact" as the new item's name and click Add. As a result, you will get an automatically generated code file with a single class declaration.

  • In general, the business class should be implemented in a platform-independent module project so WinForms and ASP.NET applications provide the same object. To add a new category, right-click MySolution module project "business objects" folder, then select "Add | Class ... to call.". "In this dialog box, the" Add New Item Contact "and specify the name of the new project, and then click" Add. "Therefore, you will get an automatically generated code files, only one class declaration.

    Add_Class_Contact

  • Replace the automatically generated class declaration with the following code.

  • The automatically generated class declaration with the following code.

    using System;
    using DevExpress.ExpressApp.DC;
    using DevExpress.Persistent.Base;
    using DevExpress.Persistent.BaseImpl.EF;
    
    namespace MySolution.Module.BusinessObjects {
        [DefaultClassOptions]
        public class Contact : Person {
            public Contact() { }
    
            public string WebPageAddress { get; set; }
            public string NickName { get; set; }
            public string SpouseName { get; set; }
            public TitleOfCourtesy TitleOfCourtesy { get; set; }
            public DateTime? Anniversary { get; set; }
            [FieldSize(4096)]
            public String Notes { get; set; }
        }
        public enum TitleOfCourtesy { Dr, Miss, Mr, Mrs, Ms };
    }

     

    As you can see, the Contact class ancestor is Person from the Business Class Library and several custom properties are implemented.

  • As you can see, touch human ancestors are from Business class library staff, and to achieve a more custom attributes.

  • Note the use of the DefaultClassOptionsAttribute attribute. In this tutorial, this attribute means that the following capabilities will be available for the Contact business class.

  • Note the use of the default class option Properties. In this tutorial, this attribute indicates the following functions can be used to contact the traffic classes.

 

    • The Contact item will be added to the main form's navigation control. When clicking this item, a List View will be displayed. This List View represents a list of objects of the Contact type.
    • The Contact item will be added to the submenu of the New (new_dropdown_btn) button when objects of another type are displayed in the List View. Click this item to invoke a Contact detail form and create a new Contact object.
    • The Contact objects will be provided as a data source to generate reports (see Create a Report in Visual Studio).
    • Contact items are added to the main form of navigation controls. When you click this item, a list view. This list represents a list view object contact type.
    • When another type of objects displayed in the list view, the contact entry is added to the sub-menu "New (new_dropdown_btn)" of the button. Click on this project can be called "contact details" and create a new form of "contact" object.
    • Contact object will be provided to generate a report (see Creating a Report in Visual Studio) as a data source.

 

  • To apply each of these options separately, use the NavigationItemAttribute, CreatableItemAttribute and VisibleInReportsAttribute attributes.

 

           To a separate application for each option, use the navigation property, operational property and visible in the report Properties.

 

  • After the class declaration, add all new business objects to the solution's DbContex

 

          After the class declaration, add all new business objects to DbContext solutions

 

  •  Since Contact is a descendant of Person, entities used in the Person class should also be registered. Edit the BusinessObjects\MySolutionDbContext.cs file as shown below.

          As the "Contact" is a descendant of Person, it should also be registered entity Person class to use. _MySolutionDbContext.cs edit business object file, as shown in FIG.

using MySolution.Module.BusinessObjects;

namespace  MySolution.Module.BusinessObjects {
    public class MySolutionDbContext : DbContext {
        //...
        public DbSet<Contact> Contacts { get; set; }
        public DbSet<Party> Parties { get; set; }
        public DbSet<Address> Addresses { get; set; }
        public DbSet<Country> Countries { get; set; }
        public DbSet<State> States { get; set; }
        public DbSet<PhoneNumber> PhoneNumbers { get; set; }
        public DbSet<Task> AssignedTasks { get; set; }
    }
}

 

  • At this step, the business model has already been declared, but if you have started the application with another version of DbContext, you will get the following error: "The model backing the 'MySolutionDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)". To avoid this error, drop the database every time you change something in the business model (create a new class, add a new attribute to an existing class, rename a class or an attribute, etc.). To do it automatically during the debug, uncomment the following code in the MySolution.Module\Module.cs file.

  • In this step, the business model has been declared, but if you are already using another version of DbContext start the application, you will get the following error: "Since the creation of the database, support for" MySolutionDbContext "context model has changed, consider using code first. are deleted when migrating to update (http://go.microsoft.com/fwlink/?LinkId=238269)* database. to avoid this error, each time you change the contents of the business model of the database (creating a new class to an existing class Add a new attribute, rename, etc.) class or attribute. to do this automatically during debugging, please cancel annotate the following code in the module MySolution.module_module_ .cs file.

    public sealed partial class MySolutionModule : ModuleBase {
        // Uncomment this code to delete and recreate the database each time the data model has changed.
        // Do not use this code in a production environment to avoid data loss.
        #if DEBUG
        static MySolutionModule() {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MySolutionDbContext>());
        }
        #endif
        //...
    }

     

  • Run the WinForms or ASP.NET application. You will see how the user interface is automatically generated using the specified data structures. A navigation control allows you to display the Contact list. You can customize this collection using the corresponding editors. If you click the New button or double-click an existing record, the application will show a detail form (Detail View) filled with editors for each data field.

  • Run WinForms or ASP.NET applications. You will see how to use the specified data structures automatically generated user interface. Navigation controls allow you to display your contact list. You can use the appropriate editor to customize this collection. If you click the "New" button or double-click an existing record, the application displays a details form (Detail view), where the editor fills each data field.

 

  • The following image demonstrates the Detail and List Views in the WinForms application.

  • The following illustration shows details and list views WinForms application.

    Tutorial_BMD_Lesson2_2

    Notice that many elements have been generated in an intuitive manner in very little time. The proper editors are created for data fields, and appropriate editors are used in the grid controls to display data. Note that a combo box editor has been created for Title Of Courtesy (an enumerator). Also note that captions have automatically been transformed from camel-case to space-separated strings, form titles are automatically updated, etc.

  • 请注意,许多元素是在非常少的时间内以直观的方式生成的。为数据字段创建适当的编辑器,并在网格控件中使用适当的编辑器来显示数据。请注意,已为礼貌标题(枚举器)创建了组合框编辑器。另请注意,标题已自动从骆驼大小写转换为空格分隔的字符串,表单标题会自动更新,等等。

 

  • You can use the grid features to show, hide and rearrange columns, and apply grouping, filtering and sorting to a List View at runtime. In the WinForms application, you can customize the editor layout on the detail form as you like at runtime. For this purpose, right-click an empty space and select Customize Layout. You can now move editors to the required positions. To learn how to customize the editor layout at design time, refer to the Customize the View Items Layout topic. Additionally, you can refer to the View Items Layout Customization and List View Column Generation topics to see how the default Detail View layout and default List View column set are generated.

  • 您可以使用网格要素来显示、隐藏和重新排列列,并在运行时对列表视图应用分组、筛选和排序。在 WinForms 应用程序中,您可以在运行时根据需要自定义详细信息窗体上的编辑器布局。为此,右键单击空白区域并选择"自定义布局"。您现在可以将编辑器移动到所需的位置。要了解如何在设计时自定义编辑器布局,请参阅自定义视图项布局主题。此外,还可以参考"查看项目布局自定义"和"列表视图列生成"主题,以查看如何生成默认"详细信息视图"布局和默认列表视图列集。

 

You can see the code demonstrated here in the MySolution.Module | Data | Contact.cs (Contact.vb) file of the EF Demo (Code First) installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst.

You can MySolution module |. Data | Contact.cs (Contact.vb) and XAF files installed with EF demo (code first) file. By default, EF demo (code first) application is installed in % the PUBLIC% \ Documents \ DevExpress the Demos 19.2 \ Components \ eXpressApp Framework \ EFDemoCodeFirst .

Guess you like

Origin www.cnblogs.com/foreachlife/p/Inherit-from-the-Business-Class-Library-Class.html