Skip to content

Commit

Permalink
⬆️ Get Started UWP => Beta 8
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanmiller committed Oct 15, 2015
1 parent a07827b commit e59bd3c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 95 deletions.
43 changes: 13 additions & 30 deletions docs/getting-started/uwp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Getting Started on Universal Windows Platform

In this walkthrough, you will build a Universal Windows Platform (UWP) application that performs basic data access against a local SQLite database using Entity Framework.

.. caution::
**Pre-releases of EF7 can be used on UWP but there are a number of known issues that you need to workaround. Look out for caution boxes (such as this one) that provide details of required workarounds.**
.. danger::
**The current pre-release of Entity Framework 7 can be used for local development of Universal Windows Applications but it can not be used in an application that is deployed to the app store.**

We'll be working to address these issues in upcoming releases. In fact, some of them are already fixed in our working code base.
This is because EF7 is not yet compatible with .NET Native, which is a hard requirement for applications deployed to the app store. You can `track our work to support .NET Native on our GitHub project <https://github.com/aspnet/EntityFramework/issues/623>`_.

In this article:
- `Prerequisites`_
Expand All @@ -18,21 +18,18 @@ In this article:

`View this article's samples on GitHub <https://github.com/aspnet/EntityFramework.Docs/tree/master/docs/getting-started/uwp/sample>`_.

.. caution::
**This walkthrough uses EF 7.0.0-beta6. Version 7.0.0-beta7 is available on NuGet.org, but some issues prevent it from being installed in a UWP application.**
.. note::
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.

Prerequisites
-------------

The following items are required to complete this walkthrough:
- Windows 10 RTM
- Visual Studio 2015 RTM with Window 10 Developer Tools

.. tip::
If you already have Visual Studio 2015 RTM installed without the Windows 10 Developer Tools, you can add these tools to your existing Visual Studio installation. You can `run the installer <http://go.microsoft.com/fwlink/?LinkID=619615>`_, or open **Programs and Features** from **Control Panel**, select **Visual Studio** and click **Change**. Then in setup, click **Modify** and select the **Tools for Universal Windows Apps**.

- Windows 10
- Visual Studio 2015
- The latest version of `Windows 10 Developer Tools <https://dev.windows.com/en-us/downloads>`_

Create a new project
--------------------
Expand All @@ -48,17 +45,11 @@ Install Entity Framework
To use EF7 you install the package for the database provider(s) you want to target. This walkthrough uses SQLite. For a list of available providers see :doc:`/providers/index`.

* :menuselection:`Tools --> NuGet Package Manager --> Package Manager Console`
* Run ``Install-Package EntityFramework.SQLite –Version 7.0.0-beta6``
* Run ``Install-Package EntityFramework.SQLite –Pre``

Later in this walkthrough we will also be using some Entity Framework commands to maintain the database. So we will install the commands package as well.

* Run ``Install-Package EntityFramework.Commands –Version 7.0.0-beta6``
* Run ``Install-Package Microsoft.CodeAnalysis.CSharp –Version 1.0.0``

.. caution::
**Note that the commands explicitly install EF 7.0.0-beta6.** Version 7.0.0-beta7 is available on NuGet.org, but some issues prevent it from being installed in a UWP application.

Needing to install the **Microsoft.CodeAnalysis.CSharp** package is a workaround for an issue in Beta 6. This will not be required in later releases.
* Run ``Install-Package EntityFramework.Commands –Pre``

Create your model
-----------------
Expand All @@ -75,6 +66,9 @@ Now it's time to define a context and entity classes that make up your model.
.. note::
Notice the ``OnConfiguring`` method (new in EF7) that is used to specify the provider to use and, optionally, other configuration too.

.. 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:: uwp/sample/EFGetStarted.UWP/Model.cs
:language: c#
:linenos:
Expand All @@ -91,17 +85,6 @@ Now that you have a model, you can use migrations to create a database for you.
.. caution::
Notice that you need to manually build the solution before running the ``Add-Migration`` command. The command does invoke the build operation on the project, but we are currently investigating why this does not result in the correct assemblies being outputted.

.. caution::
Due to a bug in the migration scaffolder in Beta6 you will need to manually edit the generated migration.

Remove (or comment out) the two calls to ``.Annotation("Sqlite:Autoincrement", true)`` as highlighted in the following code listing

.. literalinclude:: uwp/sample/EFGetStarted.UWP/Migrations/20150729201928_MyFirstMigration.cs
:language: c#
:linenos:
:lines: 10-31
:emphasize-lines: 7-8,19-20

Since we want the database to be created on the device that the app runs on, we will add some code to apply any pending migrations to the local database on application startup. The first time that the app runs, this will take care of creating the local database for us.

* Right-click on **App.xaml** in **Solution Explorer** and select **View Code**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public App()

using (var db = new BloggingContext())
{
db.Database.ApplyMigrations();
db.Database.Migrate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<NuGetPackageRoot>C:\Users\rowmil\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\EntityFramework.Commands\7.0.0-beta6\build\netcore50\EntityFramework.Commands.targets" Condition="Exists('$(NuGetPackageRoot)\EntityFramework.Commands\7.0.0-beta6\build\netcore50\EntityFramework.Commands.targets')" />
<Import Project="$(NuGetPackageRoot)\EntityFramework.Commands\7.0.0-beta8\build\uap10.0\EntityFramework.Commands.props" Condition="Exists('$(NuGetPackageRoot)\EntityFramework.Commands\7.0.0-beta8\build\uap10.0\EntityFramework.Commands.props')" />
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.Entity.Migrations;
using Microsoft.Data.Entity.Migrations.Builders;
using Microsoft.Data.Entity.Migrations.Operations;

namespace EFGetStartedUWPMigrations
namespace EFGetStarted.UWP.Migrations
{
public partial class MyFirstMigration : Migration
{
public override void Up(MigrationBuilder migration)
protected override void Up(MigrationBuilder migrationBuilder)
{
migration.CreateTable(
migrationBuilder.CreateTable(
name: "Blog",
columns: table => new
{
BlogId = table.Column(type: "INTEGER", nullable: false), // <- Add this comma
//.Annotation("Sqlite:Autoincrement", "true"), // <- Remove or comment this line
Url = table.Column(type: "TEXT", nullable: false)
BlogId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Url = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Blog", x => x.BlogId);
});
migration.CreateTable(
migrationBuilder.CreateTable(
name: "Post",
columns: table => new
{
PostId = table.Column(type: "INTEGER", nullable: false), // <- Add this comma
//.Annotation("Sqlite:Autoincrement", "true"), // <- Remove or comment this line
BlogId = table.Column(type: "INTEGER", nullable: false),
Content = table.Column(type: "TEXT", nullable: true),
Title = table.Column(type: "TEXT", nullable: true)
PostId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
BlogId = table.Column<int>(nullable: false),
Content = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Post", x => x.PostId);
table.ForeignKey(
name: "FK_Post_Blog_BlogId",
columns: x => x.BlogId,
referencedTable: "Blog",
referencedColumn: "BlogId");
column: x => x.BlogId,
principalTable: "Blog",
principalColumn: "BlogId");
});
}

public override void Down(MigrationBuilder migration)
protected override void Down(MigrationBuilder migrationBuilder)
{
migration.DropTable("Post");
migration.DropTable("Blog");
migrationBuilder.DropTable("Post");
migrationBuilder.DropTable("Blog");
}
}
}

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,31 +1,32 @@
using System;
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations.Infrastructure;
using Microsoft.Data.Entity.Migrations;
using EFGetStarted.UWP;

namespace EFGetStartedUWPMigrations
namespace EFGetStarted.UWP.Migrations
{
[ContextType(typeof(BloggingContext))]
[DbContext(typeof(BloggingContext))]
partial class BloggingContextModelSnapshot : ModelSnapshot
{
public override void BuildModel(ModelBuilder builder)
protected override void BuildModel(ModelBuilder modelBuilder)
{
builder
.Annotation("ProductVersion", "7.0.0-beta6-13815");
modelBuilder
.Annotation("ProductVersion", "7.0.0-beta8-15964");

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

builder.Entity("EFGetStarted.UWP.Post", b =>
modelBuilder.Entity("EFGetStarted.UWP.Post", b =>
{
b.Property<int>("PostId")
.ValueGeneratedOnAdd();
Expand All @@ -36,13 +37,13 @@ public override void BuildModel(ModelBuilder builder)
b.Property<string>("Title");
b.Key("PostId");
b.HasKey("PostId");
});

builder.Entity("EFGetStarted.UWP.Post", b =>
modelBuilder.Entity("EFGetStarted.UWP.Post", b =>
{
b.Reference("EFGetStarted.UWP.Blog")
.InverseCollection()
b.HasOne("EFGetStarted.UWP.Blog")
.WithMany()
.ForeignKey("BlogId");
});
}
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/uwp/sample/EFGetStarted.UWP/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
// Make Blog.Url required
modelBuilder.Entity<Blog>()
.Property(b => b.Url)
.Required();
.IsRequired();
}
}

Expand All @@ -50,4 +50,4 @@ public class Post
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
}
}
5 changes: 2 additions & 3 deletions docs/getting-started/uwp/sample/EFGetStarted.UWP/project.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta6",
"EntityFramework.SQLite": "7.0.0-beta6",
"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SQLite": "7.0.0-beta8",
"Microsoft.ApplicationInsights": "1.0.0",
"Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
"Microsoft.ApplicationInsights.WindowsApps": "1.0.0",
"Microsoft.CodeAnalysis.CSharp": "1.0.0",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
Expand Down

0 comments on commit e59bd3c

Please sign in to comment.