Rapid development of Asp. Net Mvc + ComBoost. Mvc

Source: Internet
Author: User
Tags connectionstrings

ComBoost Project address

Http://comboost.wodsoft.com

Https://github.com/Kation/ComBoost/tree/develop

Preparations

First, create an Mvc4 project in Visual Studio.

Then use NuGet to installComBoostPackage.

Compile entity

InModelsAddEmployeeGroupEmployee Group type.

EmployeeGroupInheritanceEntityBase.

[DisplayName ("Employee Group")] [DisplayColumn ("GroupName", "GroupName")] public class EmployeeGroup: entityBase {[Required] [Display (Name = "Employee Group Name", Order = 0)] public virtual string GroupName {get; set ;} [Hide] public virtual ICollection <Employee> Employees {get; set ;}}

InModelsAddEmployeeEmployee Group type.

EmployeeSame inheritanceEntityBase.

[DisplayName ("Employee")] [DisplayColumn ("Name", "Name")] public class Employee: EntityBase {[Display (Name = "Employee Name ", order = 0)] [Required] public virtual string Name {get; set;} [Display (Name = "gender", Order = 10)] [CustomDataType (CustomDataType. sex)] public virtual bool Sex {get; set;} [Required] [Display (Name = "employee ID", Order = 20)] public virtual string JobNumber {get; set;} [Column (TypeName = "datetime2")] [Display (Name = "Date of Birth", Order = 30)] public virtual DateTime Birth {get; set ;} [Display (Name = "no", Order = 40)] public virtual bool Marital {get; set;} [Required] [Display (Name = "department ", order = 50)] public virtual EmployeeGroup Group {get; set;} [Display (Name = "contact number", Order = 60)] public virtual string Tel {get; set ;} [Display (Name = "Email", Order = 70)] public virtual string Email {get; set;} [Display (Name = "QQ", Order = 80)] public virtual string QQ {get; set ;}}

 

Use EntityFramework

Install in NuGetEntityFramework.

After installationModelsFolder AdditionDataContextClass.

DataContextInheritanceEntityFrameworkOfDbContextClass.

public class DataContext : DbContext{    public DbSet<Employee> Employee { get; set; }    public DbSet<EmployeeGroup> EmployeeGroup { get; set; }}

Andweb.configAdd a data connection string to the file.

  <connectionStrings>    <add name="DataContext" connectionString="server=127.0.0.1;database=Test;Uid=sa;Pwd=123@abc;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />  </connectionStrings>

 

Last

Install in NuGetComBoost.MvcAndComBoost.Unity,ComBoost.BootstrapPackage.

Update all packages to the latest version!

ModifyApp_StartFolderUnityControllerFactory.cs

Dependency InjectionDataContextAnd register the entity controller.

public UnityControllerFactory(IUnityContainer container){    _container = container;    //Change EntityContextBuilder to your class that inherit IEntityContextBuilder interface.    //If your entity context builder has constructor with arguments, continue register types that you need.    container.RegisterType<DbContext, DataContext>(new MvcLifetimeManager());    container.RegisterType<IEntityContextBuilder, EntityContextBuilder>(new MvcLifetimeManager());    //Register your entity here:    //RegisterController<EntityType>();    //...    RegisterController<Employee>();    RegisterController<EmployeeGroup>();}

 

Complete

Now that you have created a project, you can access/EmployeeOr/EmployeeGroupAddress to edit the object.

This is the most basic example. _Layout.cshtmlYou can also create a controller to implement other functions. For more information, see the relevant documentation.

Download the sample project file: MvcSample.rar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.