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 installComBoost
Package.
Compile entity
InModels
AddEmployeeGroup
Employee Group type.
EmployeeGroup
InheritanceEntityBase
.
[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 ;}}
InModels
AddEmployee
Employee Group type.
Employee
Same 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 installationModels
Folder AdditionDataContext
Class.
DataContext
InheritanceEntityFramework
OfDbContext
Class.
public class DataContext : DbContext{ public DbSet<Employee> Employee { get; set; } public DbSet<EmployeeGroup> EmployeeGroup { get; set; }}
Andweb.config
Add 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.Mvc
AndComBoost.Unity
,ComBoost.Bootstrap
Package.
Update all packages to the latest version!
ModifyApp_Start
FolderUnityControllerFactory.cs
Dependency InjectionDataContext
And 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/Employee
Or/EmployeeGroup
Address to edit the object.
This is the most basic example.
_Layout.cshtml
You can also create a controller to implement other functions. For more information, see the relevant documentation.
Download the sample project file: MvcSample.rar