Some DDD+EF Resources

Could not fit this into a tweet in response to a request.

Here are some resources for how EF can be a partner to a Domain Driven Design world:

Video: Oredev, Fall 2013 (by me)
ENTITY FRAMEWORK IN CORE-BUSINESS APPLICATIONS THAT LEVERAGE DDD

Video: TechEd North America, May 2014 (Vaughn Vernon)
How You Can Implement Aggregates and Domain Entities Effectively in Domain Models, with .NET

Article Series:
MSDN Magazine Data Points Column (by me) Aug, Sept & Oct 2013
Coding for Domain-Driven Design: Tips for Data-Focused Devs, Part 1
Coding for Domain-Driven Design: Tips for Data-Focused Devs, Part 2
Coding for Domain-Driven Design: Tips for Data-Focused Devs, Part 3

Domain modeling with Entity Framework Scorecard (Jimmy Bogard)

Bonus for NHibernate Converts:
And for those who are looking for this by way of moving from DDD + NH, Jimmy Bogard did a great post (with pointers to related posts) on Migrating from NHibernate to EF.

DDD Fundamentals, SOON SOON

imageSteve Smith and I have been working for quite a while on a Domain-Driven Design Fundamentals course for Pluralsight. Our schedules and some interesting, unexpected but quite welcome, learning curves and most importantly, our “go big or go home” desire to refine, clarify and polish everything made this take longer to finish than either of us imagined.

In addition, the demo app that we show and evolve throughout the course – much of which is Steve’s genius – is totally kick-ass!

We are grateful that Eric Evans participated in this by chatting with us on Skype and capturing video to include throughout the course. We also are thankful for some guidance from another DDD guru, Vaughn Vernon.

The course is about 4.5 hours long, broken up into 7 modules.

The course has been done, reviewed, edited and absolutely final…ready to be published but unfortunately, so are many other new courses on Pluralsight. So the DDD Fundamentals is in the queue to get published soon.

Believe me, Steve & I will be tweeting up a storm when this thing finally goes live so watch our blogs or twitter (I’m twitter.com/julielerman, he’s twitter.com/ardalis).

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";

Highlights of Rowan Miller’s EF6/EF7 Talk at TechEd 2014

Yesterday afternoon, Channel 9 chose to broadcast the Entity Framework session presented by Rowan Miller, a Program Manager on the EF team at Microsoft. Rowan is an excellent presenter and the session was a 400 level, demo-heavy session. And it was awesome!

While the abstract promised an advanced demo-heavy session showing off features of EF6 (including the latest rev, EF6.1), Rowan also showed off some of the new functionality that will be coming in EF7.

Here are some of the highlights of his session.

The first part of the session dug into demos that showed off how you can combine features of EF6 to implement functionality that many developers would like to achieve in their applications.

The demos also used the recently released EF6.1 which has over 120 bug fixes plus a handful of new features. EF 6.1.1 is a patch release that is coming out soon. It is mostly bug fixes and some critical fixes to performance regressions that were introduced with EF 6.0.2.

The first of these was “soft deletes”, in other words for all intents & purposes, when you delete a record it is gone from the application. But it is not removed from the database. Rather than having to mark a record as “don’t show this to me again” and always include filtering in queries, Rowan showed how you can get Entity Framework to take care of these tasks in the background.  He combined the use of

  • Custom Conventions
  • Mapping Data Annotations to Custom Conventions
  • Command interceptors (for queries and change commands)
  • CommandTree Interceptor (in 6.1)

Here’s a slide where he laid out how he would pull off the whole thing:image

 

image

Next,Rowan demonstrated how you can enforce Entity Framework to automatically perform full text searches. This meant that first the database needed to have Full Text search implemented. Rowan used EF6’s Custom Migrations feature (a community contribution to EF6 Smile ) to ensure that EF migrations would change the database to have full text search enabled. Next was to change how EF queries are translated to SQL queries. This was a much trickier bit of code that benefited from the fact that with EF 6.1, the Mappng API was exposed so that we could code against it directly. The team was a little reluctant to expose that API only because it’s older EF code and quite a bit messier to work with than they would like. SO they do plan to clean it up but in the meantime, at least we have access to it. Smile

The final EF6 demo showed how to leverage the support for using Mocking frameworks more easily in EF6. In addition, Rowan has created his own APIs (not an official part of EF) to help even more (mocking DbSets is hard!) so he used his EntityFramework.Testing API in his demo.

image

And then…..EF7 (sneak peek).

So the team has started working on EF7. It is a work in progress and open-source. You can find it at github.com/aspnet/entityframework .

EF will undergo a “sea change” with this version. It is time to shed some of the 8 year old code in the APIs that is making it harder and harder for the team to evolve Entity Framework. EF6 will continue to evolve but for how long and to what degree, it’s hard to say. (My words, not Rowan’s). EF7 will absolutely introduce breaking changes. BUt the most important patterns, e.g., basic DbContext interaction, will remain in tact.

Rowan demo’d two exciting features they are working on in EF7 so far.

The first is the ability to leverage your existing knowledge of EF to interact with NoSQL databases. An important note he made was that EF will not try to whitewash the type of data store that it’s connecting to. There will be functionality that pertains to relational that may not also pertain to NoSQL and vice versa. But basic CRUD operations, change tracking etc will be familiar if you’re already used to how EF works.

The other demo was working on a Windows Phone app where the app was able to persist data on the phone using Entity Framework (to a SQLite database).

This is of course, all *very* early stuff.

Rowan was clearly very exicted to share the EF7 demos, but the EF6 demos were equally impressive.

Plus he is a natural as a presenter. It was a pleasure to watch his presentation.

You can see it yourself here:

The Channel9 page for this session is here: Entity Framework: Building Applications with Entity Framework 6

Hello World … A different type of geek podcast

imageShawn Wildermuth started recording a new type of interview podcast where he talks with some well known people in our tech community about how they got started in programming. He’s had software luminaries like Charles Petzold  and Scott Hanselman and many others you will recognize. It’s a lot of fun to hear about their beginnings and other conversation points that evolve while chatting with Shawn.

I talked with Shawn last month for episode #14 of the podcast. Many of you are familiar with the 3-week cold that’s been going around the U.S. Well I had it then so hopefully you can get past my sniffles. Smile

First look at (beta of) EF 6.1 Designer

EF6.1 is closing in on release. Along with the new DLLs that you can get via Nuget, there is a new designer that you can install into Visual Studio 2012 or 2013 via an MSI install.

Before installing, I uninstalled the EF Power Tools, because I wasn’t sure if they were included. Post install of the 6.1 Beta EF Designer, there was no indication of the power tool features in my context menu where it would normally be.

image

So it looks like this iteration of the designer won’t have the power tool features wrapped in except for the BIG one, the replacement of the reverse engineer into code first.  (So don’t uninstall those power tools! You can still use the other features like this one: my favorite).

With the new designer, when you create a new model, you now get 4 options. Two are familiar, EF Model from Database and Empty Model. The new ones are Empty Code First Model and Code First from database.

image

I chose Code First from database and pointed to AdventureWorks2012 and selected everything in the Human Resources schema.

image

This resulted in all of my new classes being created in my project, not in a folder.

image

Also, it added references to EF.

But the classes felt a little messy. So for my next model, I began with a new project folder. (note that I am only experimenting. I do not recommend having two models in the same project.)

image

Then I added the new entity model to th efolder, not the outer project. This time I selected the Person schema.

image

and all the new classes landed in my new folder

image

I prefer that. In a real app I would then separate the domain classes into their own projects and I would also put each of the models in its own project.

Let’s take a look at the domain classes that this generated.

Notice that tehre are data annotations. This is different than the EF Power Tools which put everything in fluent API code.

image

But those are annotations that are reasonable in a class since they are not solely defining a database mapping strategy.. required and stringlength can also be used by EF’s and .NET’s validation APIs. For the latter , think MVC validation.

But that’s not how this tool decides to use data annotations. Check the BusinessEntityAddress type.

image

It has annotations that drive the composite key creation and also that note database generated mappings. I wouldn’t normally put those in my domain types.

The rule that is being used by default is: any mappings that can be described with a data annotation are done that way. Everything else is done with a fluent api. None of my tables triggered any fluent api mappings. There is some discussion (started by guess who? Smile) on codeplex about making it easier to force the designer to use all fluent mappings if you want.

I was curious what Empty Code First Model gives us. It sets up a shell DbContext class. Makes sense to me.

image

I have been asking for the ability to select individual tables/views for reverse engineering an existing database into Code First context ad classes since the first public CTP of the EF Power Tools. (Here’s proof!) So even with a few things I’d like to see done differently, I am thrilled with this new designer feature.

Why?

For people building new apps with legacy databases, it is a great first step towards setting up DbContexts that  you can align with Domain Driven Design Bounded Contexts.  It gives me a nice stake in the ground to thinking within boundaries and also forcing me to think about when a customer in one context should be designed differently than a customer type in another context because they are used differently.

Any-hoo…there’s a quick first look for you. There’s still time to provide feedback to the team on the codeplex site. Go to this workitem: https://entityframework.codeplex.com/workitem/407

Also, as Erik reminds me in the comments, there is a  Visual Studio extension that provides some more extensive reverse engineer features into code first dbcontext and classes. You can find the docs, a video and the download here:  EntityFramework Reverse POCO Generator 

 

Setting my sites on Barcelona this fall for TechEd Europe 2014

imageThis will depend on getting a talk accepted, but I promise I will put my best foot forward! You may or may not know that I was supposed to give a talk at TEE 2013 in Madrid in June and follow that with a trip to Barcelona. But I had so many travel problems and after 5 hours at my airport on Monday, then trying again on Tuesday only to get stuck at O’Hare airport in Chicago with United Airlines saying they could not get me to Madrid until Thursday, I finally gave up and went home. So I’m determined to get to Barcelona this time!

.NET Rocks Interview from Phoenix is now online

Last week I flew from thednrjuliejan2014 bitterly cold Vermont out to Phoenix Arizona to join Carl Franklin & Richard Campbell in a very cool art film theater in Tempe for their Modern Apps 2013 Road Show Tour. The tour is in conjunction with Xamarin and Visual Studio.

Oh it was warm. Warn and sunny. I’m back home and it is currently warmed up to 4 degrees Fahrenheit!

I got to spend an extra day there which enabled me to see some of the scenery in the Phoenix area and visit with Esther Schindler & her hubby (and cats!) in Scottsdale who took me on a great tour into the hills (without the cats).

At the roadshow event, Carl & Richard interviewed me. We talked about Entity Framework 6, databases and the usual other fun chit chat.

The show is now online. Episode 943. You can listen to or download it here.

New Blog and New WebSite!

I’ve finally done away with my ancient asp.net 2.0 thedatafarm.com that I hadn’t paid any attention to in many years and with it also moved my blog (an early version of graffitiCMS that was starting to act up).

Both are now set up as a WordPress app which was fun to configure with plugins and widgets and not too challenging since I have played with WordPress a bit on behalf of my mom.

So this will be easier for me to maintain and add in modern goodies like the social links.

I’m grateful to a number of people who’s resources helped or inspired me:

Picking a Blog Engine

Many folks on twitter recommended their favorite blog engine. I considered Orchard, the new Ghost blog and initially thought I did not want to use WordPress. My pal Daniel Marbach worked on me on twitter for a while, mystified why I was a brick wall about my anti-Wordpress stance. (He gets the last laugh!) Ghost is new. It will run on Windows Azure. But I was staying with orcsweb (via Cytanium) and that was not an option. Michele Bustamante is loving Ghost on her new site michelebusta.com. Sebastien Ros, from Microsoft, who works on Orchard, was very supportive, even offering to do the big 10 year, 4200 blog post conversion for me. In the end, Steve Smith said two words that swayed me back to WordPress: automatic updates. Yeah I love the ease of one button click wordpress and plugin updates.

Picking a Host

I’ve been very fortunate to have my site hosted by orcsweb.com for many years. While they are one of the highest-end hosts for ASP.net sites and pricey (but oh so worth it), they had offered me free hosting as a benefit of being an ASPInsider. Otherwise, it would have been overkill for my wee web site. But thanks to the gratis hosting, I get the benefits that orcsweb has to offer. Orcsweb has a spin-off company for people like me …don’t need the power (or expense) of the premier hosting, but still want the benefit of their experience, dependibility and great customer support: Cytanium.com. So they offered to host my site on Cytanium which also sports the  Microsoft Web App Gallery for auto creating websites using frameworks like Orchard and WordPress. There are about 100 apps to choose from to install from the gallery. Setting up a new WordPress site was a snap.

Migrating 10 years worth of blogging

I have over 4000 blog posts and didn’t want to lose them. I found four resources that made this possible.

  1. Jef Kazimer‘s blog post on his Graffiti to WordPress migration was very helpful.
  2. Jon Sagara‘s Graffiti to BlogML tool. It’s just a small project that you can download and run in Visual Studio. I made one tweak to the code which was to handle some issues with the way it tried to emulate the blog URLs based on the titles. I had lots of quotations in those titles. In the end, I didn’t even need those URLs becasue I figured out how to get WordPress to format URLs just the same as they were formatted in the graffiti so my links should all (or mostly all) work. And I got the tool to create valid XML. I pointed the connection string to my sql server database and it processed all of the blog posts and comments in a matter of minutes!
  3. Once the posts are in BlogML format there is a WordPress plugin, BlogML Importer (which works fine with WordPress 3.8), that does the conversion.
  4. However it has a limit of 2MB file imports. Searching for a solution, I couldn’t believe that it was my own old Vermont pal, Dave Burke, who presented the solution Importing a Big Honkin’ BlogML.xml Into WordPress . I followed his instructions to a T and was able to pull in all of my posts and comments in 7 smaller files.

And some marketing

I left my blog in a /blog subfolder so that I can continue to have a main page on thedatafarm.com to let folks know that, as a consultant, I do like (and need) to work for a living.  It is all just one big wordpress site. Well, really a small one. The other stuff, home page, etc , are just static pages.

Plugins

I’m using a bunch of plugins. Since they are free, the least I can do is give them a nod:

plugins