Skip to content

Commit

Permalink
⬆️ Get Stated ASP.NET 5 => Beta 8
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanmiller committed Oct 15, 2015
1 parent b05e6bf commit 3eba324
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 80 deletions.
13 changes: 8 additions & 5 deletions docs/getting-started/aspnet5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In this article:
`View this article's samples on GitHub <https://github.com/aspnet/EntityFramework.Docs/tree/master/docs/getting-started/aspnet5/sample>`_.

.. note::
This walkthrough uses EF 7.0.0-beta7 which is the latest pre-release available on NuGet.org.
This walkthrough uses EF 7.0.0-beta8 which is the latest pre-release available on NuGet.org.

You can find nightly builds of the EF7 code base hosted on https://www.myget.org/F/aspnetvnext/api/v2/ but the code base is rapidly changing and we do not maintain up-to-date documentation for getting started.

Expand All @@ -27,6 +27,7 @@ Prerequisites

The following items are required to complete this walkthrough:
- Visual Studio 2015
- ASP.NET 5 Beta 8 Tools for Visual Studio

Create a new project
--------------------
Expand Down Expand Up @@ -67,7 +68,7 @@ Later in this walkthrough we will also be using some Entity Framework commands t
.. literalinclude:: aspnet5/sample/src/EFGetStarted.AspNet5/project.json
:language: json
:linenos:
:lines: 21-24
:lines: 21-25
:emphasize-lines: 3

Create your model
Expand All @@ -82,6 +83,9 @@ Now it's time to define a context and entity classes that make up your model.
- Enter **BloggingModel.cs** as the name and click **OK**
- Replace the contents of the file with the following code

.. note::
In a real application you would typically put each class from your model in a separate file. For the sake of simplicity, we are putting all the classes in one file for this tutorial.

.. literalinclude:: aspnet5/sample/src/EFGetStarted.AspNet5/Models/BloggingModel.cs
:language: c#
:linenos:
Expand Down Expand Up @@ -110,20 +114,19 @@ Now we can use the ``AddDbContext`` method to register it as a service.
.. literalinclude:: aspnet5/sample/src/EFGetStarted.AspNet5/Startup.cs
:language: c#
:linenos:
:lines: 29-38
:lines: 30-37
:emphasize-lines: 4-8

Create your database
--------------------

.. caution::

The migrations experience in ASP.NET 5 is still a work-in-progress. The following steps are overly complex and will be simplified by the time we reach a stable release.

Now that you have a model, you can use migrations to create a database for you.
- Open a command prompt (**Windows Key + R**, type **cmd**, click **OK**)
- Use the ``cd`` command to navigate to the project directory
- Run ``dnvm use 1.0.0-beta7``
- Run ``dnvm use 1.0.0-beta8``
- Run ``dnx ef migrations add MyFirstMigration`` to scaffold a migration to create the initial set of tables for your model.
- Run ``dnx ef database update`` to apply the new migration to the database. Because your database doesn't exist yet, it will be created for you before the migration is applied.

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/aspnet5/sample/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta7"
"version": "1.0.0-beta8"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.Entity.Migrations;
using Microsoft.Data.Entity.SqlServer.Metadata;
using Microsoft.Data.Entity.Metadata;

namespace EFGetStarted.AspNet5.Migrations
{
Expand All @@ -13,9 +13,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "Blog",
columns: table => new
{
BlogId = table.Column<int>(isNullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerIdentityStrategy.IdentityColumn),
Url = table.Column<string>(isNullable: false)
BlogId = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Url = table.Column<string>(nullable: false)
},
constraints: table =>
{
Expand All @@ -25,11 +25,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "Post",
columns: table => new
{
PostId = table.Column<int>(isNullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerIdentityStrategy.IdentityColumn),
BlogId = table.Column<int>(isNullable: false),
Content = table.Column<string>(isNullable: true),
Title = table.Column<string>(isNullable: true)
PostId = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
BlogId = table.Column<int>(nullable: false),
Content = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true)
},
constraints: table =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations;
using EFGetStarted.AspNet5.Models;
using Microsoft.Data.Entity.SqlServer.Metadata;

namespace EFGetStarted.AspNet5.Migrations
{
Expand All @@ -14,18 +13,18 @@ partial class BloggingContextModelSnapshot : ModelSnapshot
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.Annotation("ProductVersion", "7.0.0-beta7-15540")
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerIdentityStrategy.IdentityColumn);
.Annotation("ProductVersion", "7.0.0-beta8-15964")
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("EFGetStarted.AspNet5.Models.Blog", b =>
{
b.Property<int>("BlogId")
.ValueGeneratedOnAdd();
b.Property<string>("Url")
.Required();
.IsRequired();
b.Key("BlogId");
b.HasKey("BlogId");
});

modelBuilder.Entity("EFGetStarted.AspNet5.Models.Post", b =>
Expand All @@ -39,13 +38,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Title");
b.Key("PostId");
b.HasKey("PostId");
});

modelBuilder.Entity("EFGetStarted.AspNet5.Models.Post", b =>
{
b.Reference("EFGetStarted.AspNet5.Models.Blog")
.InverseCollection()
b.HasOne("EFGetStarted.AspNet5.Models.Blog")
.WithMany()
.ForeignKey("BlogId");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
// Make Blog.Url required
modelBuilder.Entity<Blog>()
.Property(b => b.Url)
.Required();
.IsRequired();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EFGetStarted.AspNet5")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EFGetStarted.AspNet5")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8dfc5a43-a0de-4fe6-9c51-f5afd57f314d")]
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Data.Entity;
using EFGetStarted.AspNet5.Models;
using Microsoft.Data.Entity;

namespace EFGetStarted.AspNet5
{
Expand All @@ -18,8 +18,9 @@ public class Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Expand Down Expand Up @@ -56,15 +57,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage();
app.UseDeveloperExceptionPage();
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
app.UseExceptionHandler("/Home/Error");
}

// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();

// Add static files to the request pipeline.
app.UseStaticFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
ViewBag.Title = "New Blog";
}

<h2>New Blog</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<h2>@ViewData["Title"]</h2>

<form asp-controller="Blogs" asp-action="Create" method="post" class="form-horizontal" role="form">
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div asp-validation-summary="ValidationSummary.All" class="text-danger" />
<div class="form-group">
@Html.LabelFor(model => model.Url, htmlAttributes: new { @class = "control-label col-md-2" })
<label asp-for="Url" class="col-md-2 control-label" />
<div class="col-md-10">
@Html.EditorFor(model => model.Url, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Url, "", new { @class = "text-danger" })
<input asp-for="Url" class="form-control" />
<span asp-validation-for="Url" class="text-danger" />
</div>
</div>
<div class="form-group">
Expand All @@ -25,6 +22,6 @@
</div>
</div>
</div>
}
</form>


Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h2>Blogs</h2>

<p>
@Html.ActionLink("Create New", "Create")
<a asp-controller="Blogs" asp-action="Create">Create New</a>
</p>

<table class="table">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
"version": "1.0.0-*",

"dependencies": {
"EntityFramework.Commands": "7.0.0-beta7",
"EntityFramework.SqlServer": "7.0.0-beta7",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
"Microsoft.Framework.Logging": "1.0.0-beta7",
"Microsoft.Framework.Logging.Console": "1.0.0-beta7",
"Microsoft.Framework.Logging.Debug": "1.0.0-beta7",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
"Microsoft.AspNet.Mvc": "6.0.0-beta8",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
"Microsoft.Framework.Logging": "1.0.0-beta8",
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta8"
},

"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},

Expand All @@ -31,13 +31,9 @@

"exclude": [
"wwwroot",
"node_modules",
"bower_components"
"node_modules"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
Expand Down

0 comments on commit 3eba324

Please sign in to comment.