Vs2015 mvc5 + ef6 + BootStrap (Code Generation Database), vs2015mvc5
With vs2015 coming out, friends can play new things.
For the new stuff in vs2015:
Public int ?;
Public string Name {get; set ;}= "Peter ";
I will not list them in detail here. If you want to know more, visit http://www.admin?.com/document/5605.html.
(Of course, you can directly use the new features of Baidu vs2015)
Why does mvc5 need to be put together with BootStrap here?
Because the powerful vs2015 binds mvc5 and BootStrap! Easyui was previously bound, and now easyui has more BootStrap friends.
When you create a new mvs5 project, you will see a Models. Note that the class can be used to generate tables in the database.
[DisplayName ("segment")] public class Part {[Key] public int ID {get; set;} [DisplayName ("segment name")] [Required ()] public string PartName {get; set;} [DisplayName ("segment encoding")] [Required ()] public string PartNo {get; set ;} public virtual ICollection <ApplicationForm> ApplicationForms {get; set;} public virtual ICollection <CustomerManager> CustomerManagers {get; set;} public static IEnumerable <SelectListItem> GetPartsSelectList () {var db = new CarLoanDBContext (); return db. parts. select (p => new SelectListItem {Text = p. partName, Value = p. ID. toString ()});}}View Code
The foreign key table can be like this:
Public class Contact {public int ID {get; set;} [ForeignKey ("ApplicationForm")] public int ApplicationFormID {get; set;} public virtual ApplicationForm {get; set ;} public ContactType {get; set;} [DisplayName ("Name")] [StringLength (20)] public string Name {get; set;} [DisplayName ("relationship")] public ContactsLenderRelationship Relation {get; set;} [DisplayName ("Mobile Phone")] [StringLength (15)] public string Mobile {get; set;} [StringLength (20)] [DisplayName ("residential phone")] public string HomeTelephone {get; set;} [DisplayName ("do you know this loan")] public bool IsKnow {get; set ;}}View Code
You can also:
Public class House {[ForeignKey ("ApplicationForm")] public int ID {get; set;} public virtual ApplicationForm {get; set ;} [DisplayName ("local")] public bool? HasHouse {get; set;} [DisplayName ("residential address")] [StringLength (20)] public string LiveAddress {get; set ;} [DisplayName ("local")] public bool? IsLocal {get; set;} [DisplayName ("mortgage")] public bool? IsLoan {get; set;} [DisplayName ("")] [DisplayFormat (DataFormatString = "{0: yyyy-MM}", ApplyFormatInEditMode = true)] public DateTime? BuyTime {get; set;} [DisplayName ("" ")] [StringLength (50)] public string Address {get; set;} [DisplayName (" zip code ")] [StringLength (20)] public string HousePostCode {get; set ;}}View Code
Of course, the DbContext must be inherited to generate a Table, but mvc5 will help you.
public class TestDBContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { } }
If it is just the above, I personally feel that it is not easy to use, and my friends also found out, where is the database?
In fact, as long as the project runs, the mdf file will be generated under the App_Data folder. However, it is inconvenient to view the modified database only when you run the project every time.
First, create the Migrations folder in the project directory, and create a class in it:
Internal sealed class Configuration: DbMigrationsConfiguration <Models. testDBContext> {public Configuration () {AutomaticMigrationsEnabled = true; ContextKey = "ScrollTest. models. testDBContext ";} protected override void Seed (Models. testDBContext context) {// This method will be called after migrating to the latest version. // You can use the DbSet <T>. addOrUpdate () helper extension method // to avoid creating duplicate seed data. e. g. /// context. people. addOrUpdate (// p => p. fullName, // new Person {FullName = "Andrew Peters"}, // new Person {FullName = "Brice Lambson "}, // new Person {FullName = "Rowan Miller "}//);//}}View Code
In this case, you need to use the tool-NuGet Package Manager-package Management Console
Enter
Add-migration Initial
Enter
Update-database
At this time, the mdf file will be generated under the App_Data folder. Careful friends will find that the Migrations folder has a similar
A file like 201511100627099_Initial only records the process of generating the mdf file and can be deleted.
Now, in this step, you can open the service resource manager and view the database in the data connection. Try it!