Scott Hanselman

Ultimate Developer PC 2.0 - Part 3 - UPDATE on Building a WEI 7.9 and RFC for building a GOM (God's Own Machine)

July 27, '10 Comments [28] Posted in Hardware | Podcast
Sponsored By
Big Ass Mobo As a reminder, if you're just turning in, here's our glossary:

  • WEI - Windows Experience Index. How fast is your machine? If you say "I've got a WEI 6.0" you've got a good machine, for example.
  • RFC - Request for Comments. This is crowdsourcing. I want to know what YOU think we need to do to make a machine that is so fast that it'll max out at WEI 7.9 and be a GOM.
  • GOM - God's Own Machine. If the Good Lord had a computer, it'd be a 7.9. We want to build that machine.

There have been two posts so far:

There were lots of great comments on both posts, and arguably there is more content in the comments than the posts! I want to give a big thank you to all the thoughtful people who have commented. You all know more than I do about this topic.

The point of this exercise is several-fold.

  • First, I haven't built a machine in 3 years, since the first Ultimate PC, lead by Jeff Atwood. Every Jedi should build their own lightsaber.
  • Second, it'd be interesting to see if it's easy (or how hard) to get a 7.9 WEI (the current maximum) on a machine given a $3000 limit. It's also interesting to see what a $1000 PC gets. Yes, we all realize that WEI is just one benchmark, but it's a public one and it's built into Windows, so it's interesting.
  • Third, I am not much of a gamer (I have a Xbox for that) but I do run several large 24" to 30" monitors and don't like waiting for my Windows to repaint, so do like a faster video card.

Here's some scores, some results, and some commentary.

Baseline. My Laptop.

This is the WEI my stock Lenovo W500 8Gb with an aftermarket OCZ Vertex 256gig SSD.

My W500 is a 4.6.

Using Visual Studio 2010 and building the trunk of the NerdDinner project (a smallish sized ASP.NET app) is about 3 to 4 seconds. On my new PC, building NerdDinner from scratch happens before I can say "one one-thousand." I could try it from MSBuild and the command line...

Measuring Commands with PowerShell

Here's a better way to measure. Taking Chris Tavares' vsvars32.ps2, changed slightly for Visual Studio 2010 and run under PowerShell x86, I add this to my local machine's Microsoft.PowerShell_profile.ps1. (As well as running "set-executionpolicy unrestricted" as admin. Or set it to whatever you like).

function Get-Batchfile ($file) {
$cmd = "`"$file`" & set"
cmd /c $cmd | Foreach-Object {
$p, $v = $_.split('=')
Set-Item -path env:$p -value $v
}
}

function VsVars32($version = "10.0")
{
$key = "HKLM:SOFTWARE\Microsoft\VisualStudio\" + $version
$VsKey = get-ItemProperty $key
$VsInstallPath = [System.IO.Path]::GetDirectoryName($VsKey.InstallDir)
$VsToolsDir = [System.IO.Path]::GetDirectoryName($VsInstallPath)
$VsToolsDir = [System.IO.Path]::Combine($VsToolsDir, "Tools")
$BatchFile = [System.IO.Path]::Combine($VsToolsDir, "vsvars32.bat")
Get-Batchfile $BatchFile
[System.Console]::Title = "Visual Studio " + $version + " Windows Powershell"
}

Thanks to Chris, now I can type "VsVars32" at any PowerShell prompt and I'm immediately setup with a Visual Studio Command Line environment. Just as an FYI, while MSBuild does report timings, since I'm using PowerShell, I can surround any command with "measure-command" as in.

measure-command { msbuild /t:rebuild .\NerdDinner.sln }

In this case from the command line, NerdDinner takes 1900ms on my laptop and 900ms on my desktop, so this isn't a good test as the app is far too small.

Of course, I can also run msbuild with the /m switch and get parallel builds on multi-core machines. However, since NerdDinner only has two projects, I only get a 10% performance increase. Let's try a more significant project.

The Upfront Conclusion: How about building yesterday's release of NHibernate 3.0 Alpha?

Here's the results, building NHibernate 3.0 Alpha using NHibernate.Everything.sln:

Times are in seconds Lenovo W500 w/ SSD Ultimate PC 1.0 Ultimate PC 2.0
MSBuild /t:rebuild 36.05 35.52 16.12
MSBuild /t:rebuild /m 24.98 25.57 12.53
MSBuild 6.17 6.99 3.11
MSBuild /m 5.91 6.66 2.72

Interesting that last year's laptop is very competitive with the original "Ultimate PC" from 2007 (still a beefy Quad Core) due to the laptop's new SSD.

Still, against the best numbers the new PC is effectively twice as fast or more at everything. Yesterday I was encoding a large HD video for Channel 9 and while the Lenovo took 3 hours, the new Ultimate PC 2.0 took 15 minutes. In some cases, it'll save hours on computationally intensive tasks, I believe. Additionally, for computationally intensive multi-tasking that have caused me to use multiple computers in the past, this machine has handled easily. For example, while I was encoding that video, I was also streaming live 720p HD video over Office Communicator. This takes at least 2 procs working full and slowed my Ultimate PC 1.0 down to the point of uselessness. The aggregate CPU on the new machine never went above 12% while just streaming video.

While I did go overboard on the Video Card, I'm extremely happy with the computer so far. I threw in an NVidia GTX275 I had laying around to run another 22" monitor while the GTX480 is running the 30" and a 24". The GTX480 does run hot. For you, dear reader, a GTX275 or any decent $100 card would do you just fine and you'd save a lot of money.

Here's the final parts list along with some caveats. Remember, building your own PC does come with risks, as you're sometimes putting together different companies parts and things don't always work perfectly. You can get a great 7.x WEI machine for $1000 from just about anyone.

The Parts List

Also, Shay Erlichmen wrote some Google Apps Javascript and put up a LIVE Google Spreadsheet that will scrape NewEgg's site and put up the current total of all the components. Thanks to Shay!

The Build

I built the case over two 4 hour sessions and broadcasted live to 80 of my close internet friends on UStream. A lot of really smart people helped me out on this build and offered a lot of interesting points.

The first day build went bad because of the power supply issue so we got it built, then spent hours thinking it was a motherboard issue. It was the power supply.

After we assembled the machine and before we installed any drivers, here was the first WEI score. The 1.0s happened because the standard VGA driver loaded.

1.0 WEI

After installing the Intel Chipset drivers for the Motherboard and the latest NVidia drivers, we were at 7.8 for video and 7.4 all up with the SSD holding us back.

 7.4 WEI

I moved the SSD to another SATA port as this motherboard has multiple SATA chipsets (Intel, Marvel) and installed the latest drivers. In one case, setting the BIOS to IDE instead of AHCI seemed to stick me at 5.9 for disk.

 5.9 WEI

Once I moved onto the Marvel SATA 3 controller with 6 GB/s I got 7.9 on disk. Interestingly the same drive on the Intel SATA 2 controller gets 7.7. The Marvel gets 310MB/s out of the Crucial SSD while the Intel controller gets 270MB/s.

7.8 WEI 

At this point, running everything stock and air-cooled, I have a nice 7.8 machine. I suspect I won't be able to get the Processor to 7.9 without overclocking to 4Ghz. As it is, the machine is running lovely. I wouldn't mind overclocking but I have decided against water cooling as I'm just too old and I need a machine to work 100% of the time. Pete Brown will be water cooling his, he says, so I'll be following his build. That said, if anyone wants to sit with me and chat about if it's possible to get this machine to 4Ghz using air-cooling, give me a holler. As for the graphics, I don't see how I can get to 7.9 without something drastic.

All in all, a great time was had by all. Thanks so much to everyone who helped and to all the wonderful (and waspish) commenters who made this a better experience.

Related Links:

Obligatory Taskman Screenshot!

12 procs in Taskman

Woohoo!

.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

ASP.NET MVC 3 Preview 1 Released – Channel 9 Video and Hanselminutes Podcast 224, Oh My!

July 27, '10 Comments [4] Posted in ASP.NET | ASP.NET MVC | Channel9 | Podcast | VS2010
Sponsored By

Phil and friends released ASP.NET MVC 3 Preview 1 today. I snuck into the office of Phil Haack and Morgan the Canadian Intern to talk about the release of ASP.NET MVC 3 Preview 1 and some of the cool "futures" stuff that Morgan (and our fleet of interns) is working on. This video isn't only about MVC as Morgan's working on some cool CSS Sprites stuff that works nicely in WebForms that you should check out as well.

image

Also, my two-hundred-and-twenty-fourth podcast is up and I talk more in depth with, yes, you guessed, it, Phil Haack. More detail in a less shaky-camera format.

What's new in ASP.NET MVC 3?

Note that installing ASP.NET MVC 3 won't mess up your ASP.NET MVC 2 applications.

  • Razor Syntax View Engine - Cleaner view syntax
  • Dynamic View and ViewModel properties - passing data between controllers and views using dynamic rather than a dictionary
  • "Add View" Dialog Box Supports Multiple View Engines - You two can be in this box.
  • Service Location and Dependency Injection Support - Get your DI hooked into controller factories, dependency injection, action filters and View Pages.
  • Global Filters - put filters on the all control methods
  • New JsonValueProviderFactory Class - Model bind directly to JSON-encoded data
  • Support for .NET Framework 4 Validation Attributes and IValidatableObject - Easier validation including validating one property based on another.
  • New IClientValidatable Interface - Discovering at runtime if the client supports validation.
  • Support for .NET Framework 4 Metadata Attributes - Support .NET 4 specific attributes like DisplayAttribute
  • New IMetadataAware Interface - Write your own attributes to contribute to the ModelMetadata creation process.
  • New Action Result Types - HttpNotFoundResult, HttpStatusCodeResult.
  • Permanent Redirect - More easily return 301s for Actions, Routes or any URL.

ASP.NET MVC Preview 1 Link Round-Up

Telerik is our sponsor for this show.

Hansel_Promo

Hanselminutes podcasts listeners can get $50 off any Telerik product this summer. All interested listeners should drop an email to podcast@telerik.com and mention the Hanselminutes promo and their sales team will reply with the special $50-off coupon code.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX, MVC, Silverlight,Windows Forms and WPF. Enjoy developer tools like .NET Reporting,ORM, Automated Testing Tools, Agile Project Management Tools, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visit  www.telerik.com.

Enjoy!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 222 - Art is Shipping - Designers and Developers with Jin Yang

July 16, '10 Comments [4] Posted in Podcast | Programming
Sponsored By

Random Giant Robot Picture My two-hundred-and-twenty-second podcast is up. Scott sits down with designer Jin Yang (@jzy) to talk about the fundamental differences between developers and designers. Are we a totally different breed? How should designers and developers work together? Should designers code their own sites?

NOTE: If you want to download our complete archives as a feed - that's all 219 shows, subscribe to the Complete MP3 Feed here.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

 Hansel_Promo

Hanselminutes podcasts listeners can get $50 off any Telerik product this summer. All interested listeners should drop an email to podcast@telerik.com and mention the Hanselminutes promo and their sales team will reply with the special $50-off coupon code.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Formsand WPF. Enjoy developer tools like .NET reporting,ORM,Automated Testing Tools, TFS, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visitwww.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 221 - Hanselminutiae-eight with Dan Fernandez

July 16, '10 Comments [1] Posted in Podcast
Sponsored By

image My two-hundred-and-twenty-first podcast is up. This week it's a very sick Dan Fernandez from Channel 9 who joins me on the show for a random Hanselminutiae. We talk iPads, Windows Phone 7, Hulu Plus, TimeSvr, innovation and more. Dan is the co-host of This Week on Channel 9, a random and cool weekly video show on Channel 9 that you can subscribe to here!

NOTE: If you want to download our complete archives as a feed - that's all 219 shows, subscribe to the Complete MP3 Feed here.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Hansel_Promo

Hanselminutes podcasts listeners can get $50 off any Telerik product this summer. All interested listeners should drop an email to podcast@telerik.com and mention the Hanselminutes promo and their sales team will reply with the special $50-off coupon code.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Formsand WPF. Enjoy developer tools like .NET reporting,ORM,Automated Testing Tools, TFS, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visitwww.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Simple Code First with Entity Framework 4 - Magic Unicorn Feature CTP 4

July 15, '10 Comments [54] Posted in ASP.NET | ASP.NET MVC | Data | IIS
Sponsored By

Space Needle made of LEGOMicrosoft's been releasing a number of right-sized LEGO pieces lately. In case you missed it, Betas have been announced for:

  • SQL 4 Compact Edition - It has a small embedded file-based SQL Database, and a web-server called IIS Express that's compatible with the full version of IIS.
  • "Razor" Page Syntax - A way to make pages/ViewEngine called "Razor." Your sites can be later be expanded to use all of ASP.NET MVC. It's a simple syntax that is easy to learn.
  • WebMatrix - It's a small (15 megs if you have .NET 4, 50megs if you don't) lightweight IDE for making ASP.NET or PHP websites. Good for non-pro developers.
    • It uses the WebDeploy engine to deploy apps to hosts, setting up permissions, copying databases, etc.
    • WebMatrix also has the free Search Engine Optimization Toolkit built in, so you can spider your own site and see how Search Engines see it. It'll make recommendations and store reports.
  • IIS Express - A version of the IIS 7.5 Web Server that can be run as non-admin, isn't installed as a service, that will also integrate with Visual Studio

More details to come on all this. Howver, on the tooling side, I did get a chance to talk to Damian Edwards, a developer working on some of this stuff and I put video up on Channel 9 yesterday.

There's lots of cool pieces that are packaged up with WebMatrix initially, but these pieces are interesting for pro developers as well.

Still, something's missing.

imageIn my mind, it's been too hard to talk to databases. I like LINQ to SQL and used it on the first NerdDinner version, but since EF4 sucks so much less is way better than earlier versions of EF, Jon and I updated NerdDinner to use EF. It was easy, but I would have liked to code first, and code only if I could.

Microsoft announced a new Entity Framework CTP today. It has the romantic and wonderful name "Microsoft ADO.NET Entity Framework Feature CTP4" which is lame. You can say "EF Feature CTP4" but I like "EF Magic Unicorn Edition" but that's just me. We're getting the tech better at Microsoft but still can't get naming right. Whadayagonnado? Still, it makes EF a pleasure.

It's got a lot of interesting features and choices, and while it's still a CTP, you should take a minute and check it out. 

To get a more detailed version of this walkthrough plus downloadable sample code, check out the ADO team's excellent blog post.

Quick CRUD via a Code First Model

After you install it (it won't mess up your system if you do), go and create a new whatever project. For my little example, I'll make a new ASP.NET MVC Website. It works for me better than a console app to illustrate a point.

Add a reference to Microsoft.Data.Entity.CTP.dll.

image

Make a new class, maybe in the Models folder, and name it something like Book. Add some code like this. Notice it's just code. Nothing derives from anything.

public class Book
{
[Key]
public int ISBN { get; set; }
[Required]
public string Title { get; set; }
public DateTime FirstPublished { get; set; }
public bool IsFiction { get; set; }
}

Notice I've put [Key] and [Required] on this class, but if that bothers me, I could put these kinds of declarations in a more fluent way in my database context class, in OnModelCreating.

builder.Entity<Book>().HasKey(b => b.ISBN);
builder.Entity<Book>().Property(b => b.Title).IsRequired();

To access my data, Here's a SimpleBookCatalog...

public class SimpleBookCatalog : DbContext
{
public DbSet<Book> Books { get; set; }
}

Next, I'll make a new Controller, via right|click Add Controller. I'll make a BookController.

public class BookController : Controller
{
SimpleBookCatalog db = new SimpleBookCatalog();

public ActionResult Index()
{
var books = db.Books;
return View(books);
}
...
}

I'll right click on the Index method and make an Index view. Then I'll run my app.

image

No data. What if I look in my SQL Management Studio? I got a Database created for me with a convention-based name since I didn't supply one.

SQL Management Studio with an automatically named Database

If I specified a different connection string, that DB could be anywhere.

However, if use a different database provider, like say, a SQL 4 Compact Edition one, setting it as the default in my Application_Start:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

Then when I run my app and look in my App_Data folder:

SQL Compact Edition Database file in App_Data

So I got a file based database without doing anything and I don't need SQL Server. (Yes, I can change the name, location, etc.) If I do nothing, I get a reasonable convention.

Next, I'll add two Create methods, one for a GET and one for a POST. In Create, I'll add my new book and save the changes:

public ActionResult Create()
{
return View();
}

[HttpPost]
public ActionResult Create(Book book)
{
db.Books.Add(book);
db.SaveChanges();
return RedirectToAction("Index");
}

I'll right click, Add View, and make a Create View. Run my app, look at the empty list, then click Create.

My Create Form

Click Create, and I'm redirected back to the Index page:

Book List

Back on the Index page, I can change the link to Details to use our primary key:

<%: Html.ActionLink("Details", "Details", new { id=item.ISBN })%> |

Create a Details View and add a Details method:

public ActionResult Details(int id)
{
var book = db.Books.Find(id);
return View(book);
}

See that Find method? That's there automatically. I can certainly use al the LINQy goodness as well, but as you can see, CRUD is simple. I can hook up Edit and Delete in a few minutes as well.

Here's the whole thing:

public class BooksController : Controller
{
SimpleBookCatalog db = new SimpleBookCatalog();

public ActionResult Index()
{
var books = db.Books;
return View(books);
}

// GET: /Books/Details/5
public ActionResult Details(int id)
{
var book = db.Books.Find(id);
return View(book);
}

// GET: /Books/Create
public ActionResult Create()
{
return View();
}

[HttpPost]
public ActionResult Create(Book book)
{
db.Books.Add(book);
db.SaveChanges();
return RedirectToAction("Index");
}

// GET: /Books/Edit/5
public ActionResult Edit(int id)
{
return View(db.Books.Find(id));
}

// POST: /Books/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
var book = db.Books.Find(id);
UpdateModel(book);
db.SaveChanges();
return RedirectToAction("Index");
}

// GET: /Books/Delete/5
public ActionResult Delete(int id)
{
var book = db.Books.Find(id);
return View(book);
}

// POST: /Books/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
db.Books.Remove(db.Books.Find(id));
db.SaveChanges();
return RedirectToAction("Index");
}
}

So that's a nice simple controller that uses a model that was written in just code. The database and its schema was created for me. The DbContext is LINQable with stuff like Add, Find, and Remove all just there. Plus, it's all EF under the hood, so if you need more complex stuff, you can do it.

For example, here's a more complex Code First Model with Collections, and more attributes. I show some fluent wiring up of relationships later on, although there are conventions that can assign bi-directionality based on naming.

public class Book
{
[Key]
public int ISBN { get; set; }
[Required]
public string Title { get; set; }
[Required]
public DateTime FirstPublished { get; set; }
[Required]
public bool IsFiction { get; set; }

public virtual Publisher Publisher { get; set; }
[RelatedTo(RelatedProperty="Author")]
public virtual Author Author { get; set; }
}

public class Person
{
[ScaffoldColumn(false)]
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}

public class Author : Person
{
[ScaffoldColumn(false)]
public int AuthorId { get; set; }

public virtual ICollection<Book> Books { get; set; }
}

public class Publisher
{
[ScaffoldColumn(false)]
public int PublisherId { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }

public virtual ICollection<Book> Books { get; set; }
}

public class SimpleBookCatalog : DbContext
{
public DbSet<Book> Books { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Publisher> Publishers { get; set; }
}

Also, "Magic Unicorn EF" supports DataAnnotations (or validation via Fluent interfaces), so those [Required] and [StringLength] stuff from before? Those apply not only in JavaScript, but also at the Server-side and Database persistence layers.

image

You can make your own strategies for creating databases, based on what's going on with the model, if it's changed, etc. Here's some built-in examples. Yours can do whatever you like. Here the SimpleBookCatalog is the DbContext from before.

//This is the default strategy.  It creates the DB only if it doesn't exist
Database.SetInitializer(new CreateDatabaseOnlyIfNotExists<SimpleBookCatalog>());
//Recreates the DB if the model changes but doesn't insert seed data.
Database.SetInitializer(new RecreateDatabaseIfModelChanges<SimpleBookCatalog>());
//Strategy for always recreating the DB every time the app is run.
Database.SetInitializer(new AlwaysRecreateDatabase<SimpleBookCatalog>());

Connection Strings for the SQL 4 CE provider are simpler (like, they are possible to memorize, which is amazing, considering how hard they are now). For example:

<add name="SimpleBookCatalog" connectionString="Data Source=C:\FooFoo\MyBooks.sdf" providerName="System.Data.SqlServerCe.4.0"/>

Here's some examples of fluent mappings and setting up relationships to give you an idea of the kinds of things you can do, while avoiding looking at any visual designers. It all depends on how clean you need your POCO (Plain Old CLR Objects) to be.

modelBuilder.Entity<Book>().HasKey(b => b.ISBN);
modelBuilder.Entity<Book>().HasRequired(b => b.Title);
modelBuilder.Entity<Book>().HasRequired(b => b.Author).WithMany(a => a.Books);
modelBuilder.Entity<Publisher>().Property(p => p.Name).MaxLength = 50;
modelBuilder.Entity<Author>().HasMany(a => a.Books).WithRequired();

These configurations can be batched up into a class that handles configuration for a specific entity so you can reuse them and more easily config like this.

builder.Configurations.Add(new BookConfiguration());

All this is a really basic example as a means of introduction and for my own learning, but so far I like it. It takes just a few minutes to get a lot done without much code. Since this is all Entity Framework, I can put an OData service on top of my model really quickly and then start consuming those services from iPhones or whatever.

It'll be interesting to take a sample like Nerd Dinner or MVC Music Store and change them to use Code First EF and the Razor View Engine and see if they are more readable and how many fewer lines of code they are.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.