Visual Studio has a useful snippet for creating auto-implemented properties
(properties implemented with the { get; set; } syntax shown in the previous
code.) To quickly create an auto-implemented property, type prop and press
the Tab key twice to expand the snippet and set the cursor selection on the property
type text. The default property value for this snippet is int; if you need to
change it (for example, to string, decimal, and so on) you can just type in the
new value. Next, press Tab twice to advance to the property name. After typing
that in, you can press the Enter key to advance to the end of the line. This snippet
comes in handy when you create new model classes.
www.it-
Page 80
What Is Scaffolding?
In the Adding a View section of Chapter 3, you saw that the Add View dialog allows you to select a
template, which is then used to create view code for you. This code generation is known as scaffolding,
and it can do a lot more than just create views.
Scaffolding in ASP.NET MVC can generate the boilerplate code you need for create, read, update,
and delete (CRUD) functionality in an application.
Page 84
Domain-driven design (DDD) is
one approach that teams use to tackle complex applications. Command-query
responsibility segregation (CQRS) is also a pattern gaining mindshare among teams
wrestling with diffi cult applications.
Some of the popular design patterns used in DDD and CQRS include the repository
and unit of work design patterns. For more information on these design patterns,
see http://msdn.microsoft.com/en-us/library/ff714955.aspx. One of
the advantages to the repository pattern is that you can create a formal boundary
between the data access code and the rest of your application. This boundary can
improve the ability to unit test your code, which is not one of the strengths of the
code generated by the default scaffolding (because of hard-coded dependencies on
the Entity Framework).
Page 86 book is different from VS2013 update3
Page 88
A QUICK INTRODUCTION TO ENTITY FRAMEWORK
DATA MIGRATIONS (this book is short of this section, I added below)
http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-deploy-aspnet-mvc-app-membership-oauth-sql-database/
PM> Enable-Migrations More than one context type was found in the assembly 'ProMVC5Ch4'. To enable migrations for 'ProMVC5Ch4.Models.ApplicationDbContext', use Enable-Migrations -ContextTypeName ProMVC5Ch4.Models.ApplicationDbContext. To enable migrations for 'ProMVC5Ch4.Models.ProMVC5Ch4DB', use Enable-Migrations -ContextTypeName ProMVC5Ch4.Models.ProMVC5Ch4DB. PM> Enable-Migrations -ContextTypeName ProMVC5Ch4.Models.ProMVC5Ch4DB Checking if the context targets an existing database... Code First Migrations enabled for project ProMVC5Ch4. PM> Update-Database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No pending explicit migrations. Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration. You can use the Add-Migration command to write the pending model changes to a code-based migration. PM> Add-Migration cmdlet Add-Migration at command pipeline position 1 Supply values for the following parameters: Name: Initial Scaffolding migration 'Initial'. The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration Initial' again. PM> Update-Database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying explicit migrations: [201410241500330_Initial]. Applying explicit migration: 201410241500330_Initial. Running Seed method. PM>
Put seed method in file below:
E:\Projects\test\ProMVC5Ch4\ProMVC5Ch4\Migrations\Configuration.cs
namespace ProMVC5Ch4.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using ProMVC5Ch4.Models;
internal sealed class Configuration : DbMigrationsConfiguration<ProMVC5Ch4.Models.ProMVC5Ch4DB>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(ProMVC5Ch4.Models.ProMVC5Ch4DB 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" }
// );
//
context.Artists.Add(new Artist { Name = "Al Di Meola" });
context.Genres.Add(new Genre { Name = "Jazz" });
context.Albums.Add(new Album
{
Artist = new Artist { Name = "Rush" },
Genre = new Genre { Name = "Rock" },
Price = 9.99m,
Title = "Caravan"
});
base.Seed(context);
}
}
}
To publish to Azure, need to check setting in publish to make sure it can connect to Azure SQL db
No comments:
Post a Comment