Tag Archives: EF7

Some Observations While Playing With EF7 Alpha Bits: EF7-Able Projects

You can’t install EF7 into just any project. Especially now that they are making the shift to focusing on ASP.NET 5 for it’s initial release.

Here are combinations that will work:

(Have not tried VS2012 ..)

Visual Studio 2013

.NET 4.5.1 projects only

Class Library, Client Projects (WPF, Console, Windows Forms), ASP.NET Projects, WCF

Later in 2015, EF7 will return to working with Windows Phone/Store, but for now, none of the relevant projects will host EF7 (e.g. universal apps, PCLs, etc)

Visual Studio 2015

.NET 4.5.1+ projects only

Class Library, Client Projects (WPF, Console, Windows Forms), ASP.NET Projects, WCF

ASP.NET 5 vNext Console & Class Library projects (and yes, the first sounds like an oxymoron)

image

ASP.NET apps (and if you’re looking for vNext, those are in the templates)

image

Some Observations While Playing With EF7 Alpha Bits

My first coding foray into EF7 was as a code monkey for Pranav  Rastogi from the ASP.NET team at TechEd Europe where he walked me through converting a simple EF6 app to EF7. (“Entity Framework Now and Later”, my bit starts at about 50 minutes in.) My next EF7 playtime was working through demos created by Rowan Miller (program manager on EF team) that are available here on his github account: https://github.com/rowanmiller/Demo-EF7/.

These demos depend on a snapshot in time of EF7 alpha  (EntityFramework.7.0.0-beta2-11514)  and demonstrate using EF7  & SQLite in a Windows Phone and Windows Store app as well as against a non-relational database (in this case Azure Table Storage). It also demos some other new features like batched updates, improved LINQ queries and more.

I used these same demos for a conference presentation which meant I practiced them repeatedly and modified them a bit to make sure it flowed in the way I preferred.

The bits are evolving rapidly. I’ve since been reading and writing about EF7 and played just a little but now I’m starting to have my most fun which is asking myself “what happens if I do X? what happens if I do Y?”, debugging, comparing and contrasting behaviors.

With the caveat that EF7 is still alpha and things are still evolving and shifting, I wanted to share some observations as I am playing with it.

1) InMemoryStore Before Committing to a Data Store

When you do any interaction with the DbContext even if you are not trying to query or save data, EF7 still wants you to specify the data provider in DbContext configuration.  Since I’m not yet interested in actually hitting a database, the new InMemory provider is the perfect foil!

In DbContext, I can install the entityframework.InMemory package then specify in my DbContext class that this is the provider I want to use and then I’m good to go.

protected override void OnConfiguring(DbContextOptions options)
{
  options.UseInMemoryStore();
  base.OnConfiguring(options);
}

I’d used InMemory for unit tests already but I was just using a simple console app to fiddle around EF7 with. That’s still testing, and that’s what the InMemory provider is for – testing.

What I’d like to do is be able to switch the context on-the-fly to use in memory store so I can have a single defined context with all of it’s dbsets, mappings etc and switch it easily to use my real data store or the InMemory store. So in a test project, I’d be able to say “use the context, but for these tests, use the InMemory store”. I see notes on github that this is a goal – e.g. specify provider along with connection string in a configuration file.

Rather than an enormous blog post, I’ll just publish this first bit and add more in bits and pieces …kinda how EF7 is being built anyway. Smile

What About EDMX When EF7 Arrives?

I’m getting a lot of folks asking me about the announcement that EF7 will focus on code first and there will be no support in EF7 for designer based EF models.

I’ll give my two cents, even though I do think the EF team has been pretty clear about this in both their blog post about EF7 plans 

EF7 – New Platforms, New Data Stores

and in Rowan Miller’s TechEd talk where he devoted the last 20 minutes to early look at early bits and early thoughts about EF7

Entity Framework: Building Applications with Entity Framework 6

Here’s the scoop: EF6 and the designer will continue to be available and worked on but the big effort will go into EF7 going forward. Personally, I can’t promise it will be around 10 years from now so please don’t bang down my door in 2024.

I’ve also been asked: “should I bother learning about the EDMX since it will not be in EF7?” I firmly believe that learning a bit about modeling via the designer helps get some of the concepts across for if/when you do code first modeling.

Also don’t forget about some of the 3rd party tools that provide designer support such as LLBLGenPro, Huagati Tools,  and DevArt’s Entity Developer. I’m guessing they will be moving their tools forward, though I haven’t looked into it yet.

Poking around EF7’s Solution

Of course, I wanted to stop everything and fiddle around with the early bits of EF7. Here’s a look at just getting at EF7 and the source.

EF7 Assemblies on Nuget

EF7 APIs are being built nightly and available via MyGet. You can have NuGet package manager subscribe to the proper feed by adding it into the Package Sources in Visual Studio’s Options UI. I named mine ASPNET EF7 Nightly Myget, although the feed is really for all of ASP.NET. The source url is https://www.myget.org/F/aspnetvnext/api/v2.

image

With that set up, you can pull from that source from the package manager like so:

image

Note that I’m using VS2013 and it was necessary to be sure I had the latest NuGet extension installed. I didn’t at first and got an error message (indicating the exact problem about the version) when I was trying to install the packages.

Here are the EF7 assemblies after I’ve filtered on data.entity:

image

Notice that the assemblies aren’t all in one big entityframework.dll file. You get to pick and choose the assemblies that drive big features e.g., migrations. The rest are for various ways of storing data. If you want EF7 to store data in memory only, then just grab that package. Want to use SQL Server? Grab that package.

I chose Microsoft .Data.Entity and InMemory, but then realized I didn’t know how to use InMemory. So instead, I decided to start over by downloading the full EF7 project along with its tests because I know I can learn a lot from the tests.

A Look at the EntityFramework solution

I went to the Github page for EF7 at https://github.com/aspnet/entityframework and downloaded the ZIP file for the solution.

image

You’ll find that there are no project files (e.g. csproj) in the solution and you can’t just open it up right away. In fact the solution is very minimal. Instead, each project has a project.json file with information about the dependences of that project. Here, for example, is the project.json file for the functional tests project of the solution:

image\

 

In the downloaded files, you’ll find a “build.cmd” file in the root folder. This calls another powershell file which will run through the projects, grab all of the necessary assemblies from NuGet and create the relevant csproj files for all of the projects. I’m sure it does plenty more as well.

After this is completed, open the solution and you’ll find that the Entity Framework source code has two sets of projects. One set targeted at Project K which supports projects in a lightweight manner via NuGet, the other targeted at .NET 4.5. If you look at the references in the K10 projects, you’ll find that they all point to assemblies that are in your project folders. In other words, every one of them is a NuGet package downloaded into your project. Even System.Runtime and System.Linq.

image

In the .NET 4.5 projects, you’ll find a mix of NuGet files (e.g. System.Data.Entity) and core .NET assemblies that are coming from the GAC.

image

The tests however are all .NET 4.5 based.

Here is an overview of what’s in the full solution: both sets of EntityFramework projects (InMemory, Entity, Migrations, Relational, SQLite and SqlServer). And a set of unit tests and functional tests for each of those projects:

image

The sun has come out so time to go! More to come though!

Oh, one last thing before I bolt. I found this amusing bit of test data in the tests:

customer.name = "Unikorn, The Return";