Julia Lerman's Blog, page 10
January 25, 2016
EF7 is now EF Core 1.0, Package and namespaces change too
The big news last week was that the ASP.NET 5 & EF7 stacks were renamed in an attempt to alleviate the confusion around the naming of everything under the ASP.NET 5 umbrella.
ASP.NET 5 is now ASP.NET Core 1.0
EF7 is now EF Core 1.0
The naming has been a topic of debate since each of these were introduced by Microsoft and throughout their development. The teams finally accepted that the myriad questions and complicated answers about the naming in the ASP.NET 5 stack was enough of a red flag to change the names. While it is a huge relief to many, the timing is problem for people who have invested in asp.net 5 already because the name is not just a brand but it will affect packages as well. As per the announcement on github
The Microsoft.AspNet.* packages and namespaces are changing to Microsoft.AspNetCore.*.
The EntityFramework.* packages and namespaces are changing to Microsoft.EntityFrameworkCore.*.
The version numbers of all of the above are being reset to 1.0.0-*.
Changing the namespaces this late in the game is going to be painful for devs/companies who have already been building apps and tooling on ASP.NET 5 &/or EF7. We are already on RC1 which was released in November with a go live license. .
Other than this, both ASP.NET Core & EF Core will move forward as planned. RC2 is supposed to be out sometime in February and they remain committed to the initial RTM at the end of March.
Here are the new namespace names for EF Core for RC2, as per https://github.com/aspnet/EntityFramework/tree/dev/src
In EF7
In EF Core
EntityFramework.Core
Microsoft.EntityFrameworkCore
EntityFramework.Commands
Microsoft.EntityFrameworkCore.Commands
EntityFramework.MicrosoftSqlServer
Microsoft.EntityFrameworkCore.SqlServer
EntityFramework.MicrosoftSqlServer.Design
Microsoft.EntityFrameworkCore.SqlServer.Design
EntityFramework.Relational
Microsoft.EntityFrameworkCore.Relational
EntityFramework.Relational.Design
Microsoft.EntityFrameworkCore.Relational.Design
EntityFramework.InMemory
Microsoft.EntityFrameworkCore.InMemory
EntityFramework.Sqlite
Microsoft.EntityFrameworkCore.Sqlite
EntityFramework.Sqlite.Design
Microsoft.EntityFrameworkCore.Sqlite.Design
If you are curious about what’s in EF Core, check out my EF7 Course on Pluralsight which I created during the Beta 4 …then read my recent post, EF7 Updates and Changes on Pluralsight’s blog which takes you from there to the current RC1.
December 31, 2015
Visual Studio 2015 Update 1: EXE Install vs Control Panel Install
tldr; my recommendation is to just do the update from control panel, not from the VS2015.1.exe
If you follow me on twitter (@julielerman) you may have caught one of my tantrum driven tweets yesterday about problems with IISExpress after I updated Visual Studio 2015 to Update 1.
I finally resolved my problems but not after a lot of whining, chocolate and avoidance measures (including a Doctor Who Season 9 episode).
I had been avoiding the update since a number of folks had been complaining about it taking hours and hours but I finally decided to bite the bullet.
I initially updated by downloading the vs2015.1.exe via VS2015 Extensions and running that. It didn’t take too long (20 minutes maybe) but in the end reported that Microsoft .NET Framework 4.6.1 RC Developer Pack had not been installed. This is a known issue. I restarted and installed that and was rewarded with “Successfully installed”.
Then I opened up an ASP.NET MVC5 (*not* the new asp.net) app I’d been working on and tried to run it and so began my problems with IISExpress. Visual Studio could not launch it. I won’t go into the many and various things I tried for the next few hours with hints from friends on twitter and many stackoverflow and blog posts. I even uninstalled and reinstalled IIS 10.0 Express a few times and tried various security/permission tweaks as well. I had offers from friends to jump on skype to help and finally took one of those up – thanks Gregor Suttie (@gsuttie) – though we still made no headway.
There was another strange problem that is noteworthy. Although Visual Studio’s Help/About window showed that I had the version # for Update 1 installed, the Extensions dialog continued to show Update 1 as an available update to Visual Studio. Something wasn’t in sync.
Others on twitter reported issues with Update 1, even Barry Dorrans (@blowdart) who is a security expert on the ASP.NET team and Jeff Prosise (@jprosise), a renowned .NET super duper uber expert.
I decided it was time to just uninstall and reinstall VS2015 – cleaner than a repair in my mind. Though I hadn’t yet determined if I would apply the Update 1 again.
I opened up Control Panel/Programs, found Visual Studio Enterprise in the list and selected it. I immediately got a notification that the setup program for Visual Studio had changed significatnly and did I want to update that before making any changes to the installation.
Even though my plan had been to uninstall, I decided to take that path. The update took some time … I think over 1/2 hour.
When it was done, Update 1 was one of the options listed when I chose to Modify.
FWIW, after performing the update, you can’t uncheck that option.
I selected the Update 1 and didn’t touch anything else and let ‘er rip (e.g. clicked the Update button).
It took some time to update and it was nice to see that it also brought in the latest version of the EF Designer (6.1.3) for me. “some time” ….I didn’t keep track at all …went upstairs for dinner.
When all was said and done, all of the problems I had seen via the exe install were gone. Update 1 was in place. Extensions no longer prompted me to install the update. I could debug in IISExpress again. All of my other extensions were still in place. (Update: nuget was gone, so I had to reinstall that.)
Oh and I had the new icon which many had fought so hard for:
So my recommendation is to just do the update from control panel, not from the VS2015.1.exe!!
December 22, 2015
EF7 RC1 Notes–An Update to my Pluralsight “Planning Ahead for Entity Framework 7” course
In early 2015, I published a course titled “Looking Ahead to Entity Framework 7”. This was created using an early version of the work that the EF team was doing on the total refresh of Entity Framework.
That version was referred to as Beta 4 although was still so malleable that the EF team even referred to it as an alpha. In fact, the only reason it had the tag “beta 4” was to align with the set of Nuget packages that were being released for ASP.NET 5 as it was developing. An important goal with EF7 was that it needs to work with ASP.NET 5, so the EF team needed to release their stable pre-releases on Nuget.org (e.g. http://www.nuget.org/packages/EntityFramework.Core/) in sync with ASP.NET 5. The nightly builds, which are available on https://www.myget.org/gallery/aspnetvnext are a different story and are pushed frequently by the EF team whenever they are ready to do so.
Since the course was released some technical things have changed and even the release plans have changed. Rather than updating the course each time, potentially introducing more things that will change by RTM, I will wait until EF7 is closer to RTM and use that to create a course about the release.
In the meantime, I think it is important to have some awareness of the current landscape so that combined with watching Looking Ahead to Entity Framework 7, you can plan ahead effectively. My recommendation is to at least peruse this blog post before watching the course and then come back and read it more carefully when it will make more sense.
In this post I will address each of the 6 modules of the beta 4 course and alert you to what has changed and what to expect.
Module 1: Achieving Microsoft’s Goals for EF with EF7
The overarching goals for EF7 have not changed. Microsoft is wholly committed to a completely new code base for EF7 using modern software practices. The New Devices New Data Stores goal is still correct and as you learned (or will learn when you watch the course), the proof of concept work around NoSQL and Redis is still set aside.
While discussing where you can use EF7, I showed a slide that talked about various frameworks.
This shifts a bit since the initial RTM of EF7 will now support UWP (Universal Windows Platform) which targets Windows 10 devices including phones and tablets. Along with this change, the SQLite provider that had been set aside, is now part of the initial RTM. In the course, I explained that the Windows Phone 8 & Windows Store support is also set aside for a later release after the initial RTM. That is still true.
Here is an updated version of that slide I created for a recent conference:
Another change to the first module is related to the timeline. I explained how EF7 was going to focus on being able to release alongside of ASP.NET5 which meant setting aside of of the goals that they wanted to achieve. I also explained that when ASP.NET 5 was released, we would get a release of EF7 that would be still called a pre-release, not an RTM. Here is the slide I used while discussing this timeline.
These plans have changed somewhat. While the initial ASP.NET focused release of EF7 is still going to be a subset of all that the team wants to implement in EF7, it is now going to be a full release, an RTM, not a pre-release. So at the same time ASP.NET 5 is released, EF 7.0.0 will be released.
Here is what has not changed however:
· EF 7.0.0 will still be an “abbreviated” version.
· The features that the team is focusing on are those which align well with web applications. A good example of this is that they are working on improving the experience with disconnected entities and have set aside some magical relationship features such as explicit and lazy loading.
· EF 7.0.0 will not become the “official” version of Entity Framework.
· EF6 will continue to be the official version.
· EF6 will continue to be what’s delivered when you install entityframework via Nuget.
· Your apps that use EF6 will not automatically update to EF7!
· When installing the packages via Nuget, you will not need to use “-pre” to distinguish between EF6 and EF7.
EF6 will continue to install using install-package entityframework. There is no plain old entityframework package for EF7. You would begin with your desired provider (e.g. entityframework.inmemory) and that will pull in all dependences e.g. entityframework.core and more. Since this is a full RTM for EF7, you will no longer need to use the –pre.
Also, we now have a pretty well-delineated roadmap from the EF team on their github wiki. Most importantly is that the RC1 (Release Candidate with Go-Live) version of EF7 (as well as ASP.NET5) was released in November 2015. According to the ASP.NET 5 roadmap, there will be an RC2 in February with the RTM targeted to the first quarter of 2016. There will be a big change Another notable point on the ASP.NET 5 website is the lack of Visual Basic support until possible Q3 of 2016.
According to the roadmap, EF7 will become the official version at some point in the future when the team feels that they have a critical mass of important ORM features implemented.
Here is an updated version of the above timeline slide which I used in my recent conference talk:
Module 2: Targeting EF7 Initial and Future Releases
The list of things collected in what will be in the initial release has not changed significantly except that now, as mentioned above, EF7 will also support the UWP apps.
Re VS *& .NET versions. While ASP.NET 5 can run on the DNX environment, it can also be run on a full .NET Framework environment. In the course, it says this will be possible with 4.5 and beyond. Now it will be for .NET 4.5.1 and beyond. I don’t believe that the future releases will revert back to supporting 4.5 at all.
Installing: As mentioned above, the latest stable release is available on Nuget.org. (Today that is RC1). The nightly builds are available via the myget package source (https://www.myget.org/gallery/aspnetv...). The team is currently working on RC1 in the nightly builds. Sometime this month (November 2015) a stable version of RC1 will become available on Nuget.org and that will be what you get with the “-pre” tag.
In Beta4 there was still an EF7 package named EntityFramework. That no longer exists, enabling us to use that package name to specifically target EF6. For EF7, it’s easiest to begin with the provider that you want and then this will pull down all of the relevant dependencies. So for example
install-package entityframework.sqlite” will pull down that package, the relational package (which includes migration support), the core package and others.
Don’t forget that the migrations commands are in a separate package: EntityFramework.Commands, which you need to explicitly install if you want to perform migrations in nuget or the DNX environment.
This is important: the “K Runtime” is now the “DNX runtime”.
All of the commands that you run start with dnx now, not k.
For example:
dnx ef migrations add
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Playing with the proof of concept features The support for the stripped down framework used for Windows Phone 8 and Window Store apps was set aside and is still in that state. Those DLLs are not handily available. The tricks I used in the course to access those assemblies may or may not work still. I haven’t tested. Remember though that the SQLite assembly is now part of EF7 so that’s easy to get! And if you can target Windows 10 phone & tablet apps with EF7.
Module 3: Querying and Updating with EF7 (Disconnected Graphs change!)
Most of the changes from that evolved since I created this course with beta4 are around syntax. Even in the course you could see that at first the team was renaming methods to better suit how they wish they had been named. For example, rather than have DbSet.Add and DbSet.AddRange, they modified add to just take an overload that accepted a range. But just before I pushed the course live, they changed the methods back to Add taking a single object and AddRange specifically for a range. The reason for this is to lessen the blow of changes to the API. This could be something that would be backwards compatible with EF6. There have been a number of changes like this as EF7 has evolved where some of the syntax was reverted to better align with EF6. Even behavior has shifted. Add is another example. EF6 and earlier had a pattern of [almost] always affecting full graphs when you pushed a root of a graph into the context with Add/attach/Delete or using the Entry().State property. And the effect were inconsistent. They experimented with completely separating behavior by making Add (etc) and Entry.State ONLY affect the root and then giving us a new method ChangeTracker.AddGraph soley for working with graphs. Since beta4, the team has narrowed in on a pattern that will be the final say on this matter. Here it is:
DbSet.Add, AddRange, Attach, AttachRange, Update, UpdateRange: These methods now take a new 2nd parameter which is an enum,GraphBehavior.
GraphBehavior values are IncludeDependents and SingleObject.
The default for the above methods is GraphBehavior.IncludeDependents which means that a just using it in a familiar way, e.g.:
context.Samurais.Add(myNewSamurai);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
will result in *almost* familiar behavior. THe catch (which is a good improvement, in my opinion)is that the default behavior, IncludeDependents, is literally for dependent objects. it is not going to include All Related Objects. The distinction is important. Objects in a relationship are either principal (aka “parent”, or dependent (aka “child”). In the database these are easily distinguishable because the dependent is the one that has the foreign key back to the principal.
Consider the following Principal to Dependent relationships:
Order –> Line Items
Person->Address
Category->Products
It makes sense to create a new order, add some new line items to it and then add that order graph by calling context.Orders.Add(order). In this case, all of the dependent line items will be included in the operation, i.e. marked as Added as well.
It makes sense to add an address record to a person and then add that person to the context. context.People.Add(person). Again, the dependent address would be marked as added. The category with it’s dependent products also is logical.
If for some reason you created a new line Address instance then identified it’s Person by setting someAddress.Person=somePerson, and then added that address via context.Addresses.Add(someAddress), EF7 will not mark the parent/principal object (somePerson) as Added. Adding a new address does not necessarily mean you are adding the new person so EF won’t make that presumption. I also am a fan of building my model with aggregate roots that are in charge of the behavior of their related data. So I wouldn’t allow my tyeps to be used in such a way that the user of my API could create an address and randomly add it anyway. So this behavior aligns with coding patterns that I recommend.
It also solves another problem I see a lot where devs use object instances to specify reference properties. I always recommend using foreign key properties for this but I know that so many programmers have the following problem.
Imagine this scenario:
The form for building or editing the order has a place to enter the a new shipping address for a customer. One of those fields is a dropdown for “region” (in my case, in the U.S. that would be a state like Vermont or Utah). I query for a list of region objects and populate a dropdown list.
I select Vermont and then my code does something like this: theOrder.theAddress.Region=(region)List.SelectedItem. I add the order with context.Orders.Add(theOrder) and call SaveChanges.
The next person who goes to add an address sees this:
Two Vermonts! That’s because in EF6 (and earlier) everything in the graph is marked added and the EF inserts the Vermont object into the database even though it was already there.
In this case, the model sees REGION as the principal and ADDRESS as the dependent because ADDRESS has a foreign key back to REGION. EF7 will not include the principal. Only the address will get inserted and the crops are saved!
Add, Attach & Update: Root Only
So, the default for Add, AddRange, Update, UpdateRange, Attach and AttachRange is to include dependents. Using the parameter, you can specify the SingleObject enum and then only the root entity of the graph will be affected by the method.
DbContext.Entry().State
In RC1 this is the same as I explained in the course: if you specify an entity that is in a graph, only that entity will be affected by setting the state. Any other objects that are part of the graph will be untouched.
ChangeTracker.AddGraph has changed to ChangeTracker.TrackGraph
The signature is the same, you pass in the graph and a lambda function. The lambda can express the state that you want the graph to use.
context.ChangeTracker.TrackGraph(someEntityWithRelatedObjectsAttached, e => e.Entry.State = EntityState.Added);
EF will walk the graph and apply that function to everything it discovers in the graph, skipping objects that are already being tracked (and their related objects). A cool feature of this method (same as when it was called AddGraph) is that that function does not have to express state. It can be any function you want.
The DbSet.Find method
This was set aside for post-RTM, but the team is reconsidering and may get it in for RTM. More here: https://github.com/aspnet/EntityFramework/issues/797
Module 4: Using and Migrating Relational Databases
In this module I talked about some differences between how migrations worked relative to how we are used to them working in EF 4.3 to EF6. I also showed how migrations work in the k runtime commands if you are using ASP.NET 5 and not able to use the familiar PowerShell commands. I also explained that the magic behavior of the DbInitializers as well as automatic migrations will not be part of EF7.
Not a lot has changed since the beta4 release that the course is based on. The team has streamlined the commands a bit more. They had introduced a new “apply-migration” command to replace update-database, but apply-migration is gone and you will just use the familiar update-database command.
On the ASP.NET side, the commands are now dnx commands, not k commands. So the current way to express adding a migration, therefore is:
dnx ef migrations add myAwesomeMigration
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Not much else has changed from what is explained in Module 4.
There’s a nice chart in the July 23rd EF design meeting notes that shows the changes.
Not really migrating, but the commands now support reverse engineering with a scaffold command that has a bunch of helpful parameters to customize how the code is generated.
Module 5: EF7 Futures
This module covers things that the team was exploring but set aside to focus on the ASP.NET 5 aligned release. Those were non-relational stores (with Redis and Azure Table Storage as their proof of concept) and allowing EF to run on the trimmed down version of .NET that is used for Windows 8 phone and tablet (aka “windows store”) apps which also relied on the new SQLite provider. Since the assemblies were still accessible, I showed a demo of a Windows Phone and Windows Store app that used SQLite as well as one that used Azure Table Storage.
The Azure Table Storage and Redis providers are still set aside, as I explained in this module.
And while it is still true that EF7 will not initially support this Windows 8 Phone and Store apps when it is released, the team did bring SQLite back into the fold for EF 7.0.0. The reason that SQLite was re-ignited is because, as I mentioned above, EF7 is now able to run on UWP (Universal Windows Platform) the Windows 10 platform that lets us create cross-device apps that will also run on phones and tablets. Those will benefit from using SQLite. In fact, I was able to rebuild the Cookie App from this module in UWP with EF7 and SQLite and watch it run on emulators for phones and tablets.
Module 6: Interacting with the Team
This module is about how EF7 is being developed openly on GitHub at github.com/aspnet/entityframework and the story has not changed. The team continues to be eager to have developers try out EF7 and provide feedback in the form of issues or even Pull Requests. They continue to publish their team meeting notes on the wiki where we can converse with them further about their ideas.
The EF7 RoadMap
The roadmap did not exist when I created the course. It is a great resource and I encourage you to check it out at https://github.com/aspnet/EntityFramework/wiki/Roadmap.
I continue to bang on EF7 and pester the team when I’m confused. When EF 7.0.0 releases, I will create a Getting Started course that will dig further into EF7 as a full released framework.
A Few Notes About Mappings
Since the course there were a few things I learned that either didn’t exist at the time or I just didn’t know about that I think are worth mentioning.
The pluralization support we’ve been used to in the past does not exist in EF7. If you have a model with an entity named Person and another name Order, EF (& migrations) will presume that the relevant tables are also named Person and Order.
The next point will help you address the pluralization.
Custom Conventions that we got in EF6 are not in RC1 and won’t be in the first itereation of EF 7. They are targeted towards a future release — and should be in EF7 by the time it becomes the “official” version of EF.
So a custom convention such as this is not yet possible:
(EF6->) modelBuilder.Properties().Configure(p => p.HasMaxLength(50))
However, Rowan Miller points out in his gist (https://gist.github.com/rowanmiller/88261afd0baae7fb9b04) that we can continue to use a hack that we had before custom conventions existed to help (but not magically solve) with table name pluralization. And thanks to the new Name property introduced in C#6 (& VB but remember, we don’t have VB support yet) you could iterate through the entities and apply someo rules. This gist of Rowan’s shows a simplistic “add s” rule:
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
modelBuilder.Entity(entity.Name).ToTable(entity.Name + “s”);
}
Support for Table per Hierarchy (TPH) mappings was added as of RC1.
EF7 can now infer 1:1 mappings without you having to specify the principal and dependent. If it doesn’t get it right then you can use updated HasMany/HasOne fluent mappings. (These have been simplified!)
January 5, 2015
Some Observations While Playing With EF7 Alpha Bits: Current vs On-Hold APIs
Some Observations While Playing With EF7 Alpha Bits: EF7-Able Projects (Jan 5)
You may or may not have caught this important blog post from the EF team about plans for the first RTM of EF7: EF7 – Priorities, Focus, and Initial Release. In it, EF Program Manager, Rowan Miller explains that for its initial release, EF7 will target ASP.NET 5, ensuring that ASP.NET 5 has a solid data platform to release with. It also means setting aside some of the proof of concept work that the team has been working on for it’s “new platforms, new data stores” initiative. Namely, Windows Store & Windows Phone and the non-relational providers that the team has been experimenting with are on hold until after the initial RTM of EF7. This does *not* mean that they are being dropped, just delayed so that the team can focus on shipping something usable sooner. Rowan is also clear about the fact that EF7 will not be considered the “go-to” EF version until much later when they’ve brought these other features in as well as forged ahead with more parity with EF6. I recommend that you read that post.
So what does that mean with respect to the source code for EF7 on Github and the current preview Nuget packages of EF?
Note that I have a package source that is pointed to the ASPNET vNext packages which is also where EF7 lives on myget: https://www.myget.org/F/aspnetvnext/api/v2
Also that I have selected PRERELEASE packages:
And using the console, that means always adding the “-pre” parameter after the install-package command (e.g. install-package entityframework –pre).
First, here’s a look at what DLLs were on Nuget prior to the shift
The shift occurred when the nuget packages went from being tagged as alpha to being tagged as RC. Note that these nuget tags do not reflect the state of EF7, but a package naming decision.
Notice that the AzureTableStorage, Redis and SQLite packages are still there but they are from Dec 1, 2014.
Notice the addition of EntityFramework.Core. That’s where all of the core bits are now. But the entityframework package is still there. You still start by installing entityframework.
The entityframework package has a dependency on entityframework commands and will pull that in and then that forces nuget to also pull in entityframework.core, relational and migrations. You’ll need to explicitly install entityframework.SqlServer or InMemory if you want them. You’ll need at least one of those.
When you install EF7 from the ASPNetVNext package source, when the installation is finished the following HTML page will pop up in Visual Studio:
I have not tried to use the older providers. They are not going to be kept in sync with the moving forward packages. They will get caught up after EF7 has its initial release.
Also, you do have the ability to get at the source code as it was prior to this big shift. Check the “futures” branch on github:
https://github.com/aspnet/EntityFramework/tree/futures
I believe this is a snapshot that was taken prior to the shift.
Unfortunately, it’s not possible to keep all previous versions of packages on MyGet the way it is on Nuget. You can get a snapshot of the beta2.11514 packages that Rowan Miller set aside for his Connect demos. https://github.com/rowanmiller/Demo-EF7/ That’s not the latest version of EF7 prior to the shift but close.
Just remember, it is all still early early, evolving and changing rapidly.
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)
ASP.NET apps (and if you’re looking for vNext, those are in the templates)
December 27, 2014
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.
November 11, 2014
EF6 Ninja Edition Course is Live on Pluralsight
It’s been a long haul and a long wait. I started work on this course, then switched gears to work on the Domain–Driven Design Fundamentals course with Steve Smith. When I returned to work on the EF6 course, a number of minor releases and patch releases had been published so I had to revise much of what I had already recorded, edited and produced.
But today, finally, the full course has been published on Pluralsight.
Entity Framework 6: Ninja Edition
– What’s New in EF6
It is a little over 7 hours long. This is what I would have done had I written another huge book. So if you are looking for my next book, just watch this course! And you can go back to it for reference.
If you don’t have a Pluralsight subscription (and honestly, the $29 monthly fee if you were to just subscribe to watch this course, is less than those huge books), send me a note and I’ll send you a code for a trial. You’ll probably realize quickly that you want a subscription though to continue accessing the enormous library.
Course Description
Entity Framework 6 brings major improvements to EF that allow developers to align their data access with advanced software practices. The biggest news for EF6 is that it is open-source and has gained a lot from developer community input. Features with broad appeal such as stored procedure mapping in code first, support for the Async/Await pattern when executing queries and commands, simpler patterns for unit testing, and built-in database logging capabilities have gotten a lot of visibility. EF6 is now very extensible with custom Migrations, custom mapping conventions, and the introduction of Dependency Injection patterns to open up low-level DbContext configuration. There are new methods and properties that allow simpler and smarter coding patterns. Rather than present a high level list of the new features, this course dives into each new feature in EF6, ensures that you understand not only what it is for, but how it works, scenarios where you can benefit from it, and gotchas you should watch out for. This course provides a comprehensive look at what EF6 adds to Entity Framework, and it will leave you with the ability to truly benefit from all of the Ninja power that’s been added to this version of EF.
Course Outline
Overview of What’s New in EF6
Introduction
What Is Entity Framework?
What’s in This Course?
What’s in This Module?
A Brief History of Entity Framework
Why EF6?
A Lap Around EF’s CodePlex Site
Overview of Changes to the EF Designer
Overview of New Features
What’s Not (Yet) in EF6
Summary
Resources
Getting to EF6
Introduction
In This Module
Getting EF6 Into New and Old Projects
Updating Projects to EF6
Summary
Resources
Performance and Stability Improvements
Introduction
In This Module
Faster Processing of LINQ’s Enumerable Contains
Faster Mapping View Generation
Using nGen to ‘Pre-JIT’ EF6 Assembly
Reuse Open Database Connections
Create DBs That Are More Scalable and Less Prone to Deadlocks
Connection Resiliency for Transient Database Connections
Digging into the Connection Resiliency Feature
Quick Review
Resources
Changes to the EF Tooling
Introduction
EF Designer History
In This Module
EF Designer’s New MSI Installer
Creating a Code First Model From a Database in the Designer
Database Views in Your Code First Model
Customizing the Code First Designer Templates
Refactoring the Generated POCOs and Model
A Warning About a Naming Conflict With Code First From Database
What Does the Empty Code First Model Wizard Do?
Comparing the Code First Model Wizard to the EF Power Tools
Using EF4 or EF5 With the New Designer
A Notable Change to the Model First Workflow
Why You Still Need the EF Power Tools
Quick Review
Resources
Stored Procedure Mappings for Code First
Introduction
In This Module
Understanding EF Stored Procedure Mappings
Visualizing Stored Procedure Mappings
Differences Between Designer-Based and Code First Model Mappings
Conventions for Procedures Created by Code First
Customizing Mappings to Work With Existing Stored Procedures
Quick Review
Resources
Custom Code First Conventions
Introduction
In This Module
Custom Code First Conventions: Why Would You Want Them?
Custom Conventions Basics With Lightweight Conventions
Using Attributes to Specify Custom Conventions
Encapsulating Custom Conventions
Understanding and Controlling Execution Order
Model-Based Conventions
Extending Existing Conventions
Quick Review
Resources
More Code First Goodies
Introduction
In This Module
Database Index Support in Code First
Adding Indexes With Fluent API
Setting the Default Database Schema
Using AddFromAssembly to Load Conventions and Configurations
Understanding and Fixing How Code First Pluralizes Table Names
Using a PluralizationService to Localize Non-English Table Names
Implementing a Custom Pluralization Rule in Your Data Layer
Mapping to Results of Table Value Functions and Stored Procedures
Quick Review
Resources
Enhancements to Code First Migrations
Introduction
In This Module
Affecting the Schema of the Migrations History Table
Smarter Migrations With Idempotent Scripts
Limitations of Existing Migrations Methods
How Migrations Get From Method to SQL
Create Custom Migrations for Other Database Operations
Why HasColumnAnnotation and HasTableAnnotation?
Implementing a Simple Table Annotation
Implementing More Complicated Annotations
Performance Tweak for MigrateDatabaseToLatestVersion Initializer
Migrate From Multiple Models to a Single Database
Using HasDefaultSchema and ContextKey for Multiple Model Support
Easier Migrations for Multiple Models in a Single Project
Combining Database Initializers and Migrations
Quick Review
Resources
Improved Database Interaction
Introduction
In This Module
Simple Database Logging With the Log Property
Tweaking the Log Functionality
SQLCE Functions for LINQ Queries
Introducing the Async EF6 Methods
Demonstrating the Effect of Asynchronous EF6 Methods
Perception and Performance: Load Testing With Async EF6
Quick Review
Resources
Code-Based DbContext Configurations and Interceptors
Introduction
Why DbConfiguration?
In This Module
Creating and Triggering a DbConfiguration Class
Why Move Config File Settings to Code?
Moving Connection Factory to DbConfiguration
Moving Database Initializers to DbConfiguration
The New NullDatabaseIntializer
Provider Services and DbConfiguration
Tap into the Pipeline With Interceptors
Beyond the Interceptor Basics
What Stops Does the DbCommandInterceptor Make in the Pipeline?
Building an Interceptor for Database Logging
Using Interceptors to Solve Complex Problems
Understanding the Role of Dependency Resolution
Hosting DbConfiguration in External Assemblies
Quick Review
Resources
Sometimes It’s the Little Things
Introduction
In This Module
EF6 and Mocking Frameworks
Writing Tests to Mock Methods Like DbSet.Find
Writing Tests to Mock LINQ Queries
Nested Entities and Complex Types
Fixing the Ambiguous Types Problem
Custom Equals vs. Change Tracker Equals
Smarter LINQ to Entities Queries
Yes, You Can Haz Changes With HasChanges
Quick Review
Resources
October 18, 2014
My TechEd Europe Schedule
I’m so very excited to be heading to Barcelona shortly for TechEd Europe. You may or may not be aware of my dashed hopes last year when I was scheduled to speak at TechEd Europe in Madrid. But when I found myself stuck in the Chicago O’Hare airport on my 2nd day of travel, only to be told I wouldn’t get to Madrid until Thursday afternoon (after 4 days of travel) it was time to turn around and go home. I also had scheduled a post event side trip to Barcelona – this too, I canceled.
I was a little surprised that TechEd was willing to try again considering my bad history but I will be speaking at the 2014 version of the event.
Not only am I looking forward to my first ever trip to Spain and the amazing city of Barcelona, but it will be my first opportunity to meet so many developers that I’ve never met before.
My Session
My talk is on Friday, Oct 31 at 12-1:15pm. Yes, on Halloween!
Entity Framework Model Partitioning in Domain-Driven Design Bounded Contexts
Bounded Context is one of the most critical patterns in Domain-Driven Design (DDD). While you shouldn’t have to worry about your data persistence while you are modeling your domain, it is still worrisome to follow DDD patterns not knowing how you’ll get your ORM to fall in line when it’s time to implement the data layer. Entity Framework sample solutions have a long history of creating one huge model to map to one huge database to satisfy all of the needs of your application. In this session we look at patterns using Entity Framework that will support not only multiple bounded contexts in your software but even those areas that are satisfied with pure CRUD logic. You also see patterns to bridge the divides between those bounded contexts when implementing the data persistence with Entity Framework.
Getting the Most Out of My Session
Dino Esposito will be doing a relevant talk on Tuesday that will be useful if you are new to Domain-Driven Design.
DEV-B211 Architecting and Implementing Domain-Driven Design Patterns with Microsoft .NET Tuesday, October 28 1:30 PM – 2:45 PM Room: Hall 8.1 Room G
I’d also recommend watching the Domain-Driven Design Fundamentals course that Steve Smith and I created for Pluralsight. It’s about 4 hours long and is a great first look as well as a refresher on some of the key concepts of DDD. You’ll definitely get a lot more out of my talk if you’ve seen this in advance. If you don’t have a subscription to Pluralsight, send me a note and I can get you a 30 day trial code.
Where to Find Me
Here is my current schedule. This does not list talks I plan to attend, but the opportunities I will have to meet people and geek out!
So much bling, I just can’t choose!
October 2, 2014
A Pattern for Sharing Data Across Domain-Driven Design Bounded Contexts
My latest MSDN Magazine column – October 2014 issue – has just gone live.
A Pattern for Sharing Data Across Domain-Driven Design Bounded Contexts
Julie Lerman explores a way to mirror data as one scenario for sharing data across DDD bounded contexts.
Even though the solution is available for download, it involves installing and running RabbitMQ and learning my way around the server’s UI. For me that was a fun and almost freeing step of building the solution. It even meant installing Erlang on my laptop. Lots of fun but lots of learning curves.
But it may be more than some readers want to commit to. So I recorded a video of me debugging through the solution so that you can see how it works.
I recommend reading the article first and watching the Domain-Driven Fundamentals course that Steve Smith and I created for Pluralsight will really help. If you don’t have a Pluralsight subscription yet (really?) send me a message through my contact form and I can hook you up with a free trial. Warning…can lead to addiction.
Anyway, here is the video. There is no sound…I’ve used captions to explain.
September 15, 2014
DDD Fundamentals Course is Making a Difference
Steve Smith and I are so happy to be getting this kind of feedback about our Domain-Driven Fundamentals course on Pluralsight. We wanted to give developers help understanding the basics so that they can dig in to more indepth resources like Eric Evans’ or Vaughn Vernon’s books.
Here are some recent tweets we’ve seen.
Ryan Moseley @bahamaboy85
Completed the DDD Fundamentals course from @pluralsight by @ardalis @julielerman http://pluralsight.com/courses/domain... …. This course makes DDD accessible.
It is tough to find DDD examples that don’t assume some level of knowledge. So this course is welcomed.
Tom Davis @photomoose · Sep 9
@julielerman Just watched your DDD course on @pluralsight. Probably the best intro to DDD I’ve seen; things make sense now!
[image error]Paul Hale @paulhale · Aug 29
@pluralsight @ardalis @julielerman cracking #DDD course + @ericevans0 book set me on right track. Ironically Im building a domain reg system
Félix-A. Bourbonnais @fbourbonnais · Aug 11
Good #DDDDesign course by @julielerman @ardalis. Key concepts of DDD are well explained. I recommend http://owl.li/AcX4q
Geoff Mazeroff @geoffmazeroff · Jul 30
My work project uses DDD, so I enjoyed hearing @ardalis and @julielerman present the fundamentals on their @Pluralsight course. Nice work!
Mike Sussman @mikesussman · Jul 25
Finished @pluralsight DDD Fundamentals course by @julielerman and @ardalis, makes a lot more sense now.
Julia Lerman's Blog
- Julia Lerman's profile
- 18 followers
