OpenWest Conference

For the past several years, the Utah Open Source community has come together for the Utah Open Source Conference. This year, it has a different name as it grows and works to become a regional conference. Welcome to OpenWest Conference! This year, OpenWest is being held on the campus of Utah Valley University in Orem. It’s going on now through Saturday. In three days of great content you’ll hear about all sorts of Open Source goodness.

I will be speaking there too. My session, “Ooey GUI Web” is set for 11:00  11:00, in room SB276. This session will cover several Open Source web UI widgets including JQueryUI, Wijmo Open (the Open Source version of Component One‘s great Wijmo line), and JQuery DataTables. Come and find out how easy it is to add these great widgets to your web pages.


Boise Code Camp 2013

The vendor area contained several tables from companies trying to reWP_20130316_002cruit or sell their products. To encourage you to visit the vendors, each attendee got a “bingo” card. At each vendor table, you got a sticker put in designated square on the bingo card. You then had to write your name on the card and drop it in a box to be entered into a drawing for a Star Wars Xbox. The drawing would be held at the end of the day.

Each attendee also got one raffle ticket to drop in the box for the prize of your choice. Various component vendors had donated prizes as well as copy of Windows 8 Pro and a one year subscription to Pluralsight. These drawings were also made at the end of day.

My trip started Friday with a drive to Boise from Salt Lake City. Less than five hours later, I was checked into my hotel across the street from BSU. I wasn’t there long. The speaker dinner was scheduled for the evening at Fuddruckers. It was good to see old friends and meet new people. After downing a burger, it was time to stuff the attendee bags. Then, it was back to the hotel. A good sleep the night before a presentation helps make it better.WP_20130316_001

Saturday morning kicked off with breakfast and an opening session where we were welcomed and last minute announcements made. The schedule had 10 simultaneous 75-minute sessions across five time slots. I checked in, got my attendee bag, then headed for the green room. Just outside the speaker room, I saw a sign directing people to a prayer meeting. Somehow, it seemed appropriate. Inside, the speaker room was stocked with snacks, water, and even antacid.

I opted for “Designing Web Applications” presented by Nathan Barry. He pointed out that a web application is different than a web site. A web site is something you visit once in a while. A web application is something you use day-in and day-out to do your job. You may WP_20130316_005-aspend most of you day working in it. It’s more important that a web application be rock solid because if not, it will affect the user all the time. He talked about wire frames and how to use them to mock up your site. He prefers pen and paper over electronic wire frames. He also talked about the importance of consistency and menu placement. I had to leave the session early because I had the next session.

My first session of the day was in the second time slot. I really enjoy the “Software Gardening” session and attendees again told me how much they enjoyed it. Thank you for those words. Software Gardening is the premise that creating software is not like constructing a building. Software is more organic, changing in unexpected ways at unexpected time. Software is more like gardening and needs the same care and treatment. Good soil, water, light, weeding, fertilizing, and other gardening concepts also apply to software development.

After the standard pizza lunch (it’s cheap and easy to feed 500 people this way), I had my second session, “Ooey GUI Web”. This is a new session this year. I cover the basics of JQueryUI, Wijmo, and JQuery DataTables. The session went a bit rough. It was the first time I had given it. But several attendees talked to me afterwards with suggestions for improvement.

After my session, I attended “Building Better Software with TDD” presented by Richard Clements. It’s an important topic but I’d never seen Richard present. I’m glad I was there. He talked not only about the philosophy of TDD, but also the practical. He showed several examples of TDD in action and why you want to develop your applications using TDD.

The final session was “Scrum Challenges” by Richard Hundhausen. The session was presented in a agile way. Attendees wrote questions or problems they have with Scrum on Post-It Notes, which were then put on the front of the podium. Rich would select one and we’d discuss it, then move to another question. It was very effective. One important thing I got out of this session is that there is no such thing as Sprint 0, meaning you don’t plan before you start work. You only plan and design far enough ahead to deal with the first Sprint. Each Sprint after that, you update the design to handle the code you’re writing. Remember, running code is the most important thing to come out of the Sprint.

After the final session, all attendees congregated for the prize drawings. Several companies donated software or hardware. Unfortunately, I didn’t win.

Boise Code Camp was a great day of learning and networking. I hope to make it back again next year.

WP_20130316_006 WP_20130316_009 WP_20130316_007WP_20130316_003


What’s that smell? Code Camp season!

Ahhh.. spring. What a great time of the year. Days are getting longer..and warmer. The smell of rain storms and fresh flowers fill the air. The only bad thing about spring is that is means the end of ski season. But I smell something else. Spring also means Code Camp season is beginning. And I like that.

I’m kicking off my Code Camps tomorrow with a visit to Boise. Boise Code Camp is a great event held on the Boise State University Campus. I don’t like the Smurf Turf, but the tech community in Boise is great.

I’m giving two presentations. The first is a encore presentation of Software Gardening. Here’s the description:

Creating great software is not like construction. It’s more like gardening. In this session you will learn about important software gardening concepts such as soil, water, seeds, light, pruning, insecticide, weeding, and more. Along the way you’ll see processes, concepts, tools, and techniques that you can use in your software gardening project. By applying the ideas presented in this session, your software will be lush, green, and vibrant. This session has often been named “best of Code Camp” by attendees.

The second is a brand new, first time presentations, Ooey GUI Web.

Having a good, consistent, clean UI is important, but how do you do this? In this session we’ll look at free UI widgets to get you going. You’ll see how easy it is to add these widgets to your web pages and see some customization on them too. Along the way we’ll visit jQuery UI, Wijmo Open and more. A basic understanding of jQuery is recommended but not required.

I’m not sure of the times and rooms for these sessions as the schedule isn’t online, but out these sessions. I’m sure you’ll learn something from them.

 


Win money for your apps!

Want to win money for your Windows 8 or Windows Phone apps? Now you can! In addition to earning money with every sale (I know of people who pay their rent every month with what they earn), you can win up to $1000! Just click the picture below.

Win cash prizes


Followup from CodeRetreat

WP_20121208_003

Code Retreat gets underway at Pluralsight in Lehi, Utah

Last Saturday, as part of the Global Day of Coderetreat (GDCR), Utah held it’s third Coderetreat. I was unable to attend the first two so I was looking forward to the day’s activities. Coderetreat was started by Corey Haines as a “day-long intensive practice event, focusing on the fundamentals of software development and design.” In other words, you should come out of Coderetreat being able to write better code. The idea of GDCR is for multiple locations around the world to host the event on the same day. This year, around 160 cities world wide had events. There were 41 locations in US, with three in Utah. Two were hosted by Pluralsight and the other by Domo. I opted to attend the one at the Pluralsight office in Lehi. Thanks to @davidadsit for organizing the local events and @utahkay for facilitating the location I attended. Also, thanks to the host companies and the other sponsors for making the day possible.

So, what was the day like? It was all hands-on. Each person brought their own laptop and got it setup. Kay did an introduction and told us that we’d be working in pairs and have six rounds of coding. Each round would be spent with a different partner. Most attendees were C# developers, but we also had someone doing SmallTalk, Objective C, and even one person trying F# during the day. Each session we were to work on Conway’s Game of Life. The goal was not to solve the problem, but use TDD and pair programming to work through the problem. We only had 45 minutes to work, so solving the problem was not going to happen. As we went along, each session had some issues thrown into to mix things up and add some challenges. For example, we couldn’t use parameters or primitive types. Or, there were Zombies, that is, when a cell died, it stayed dead for three iterations, then came to life.

People have asked me if it was worth taking a Saturday of my time to do this. I will say absolutely. I walked our mentally exhausted, but the learning and professional improvement is still with me. I hope to attend again next year.


Why Kyro Beshay should shut up about “Metro”

Kyro Beshay (who ever he? is) should shutup. In a recent blog post, Kyro (I can’t use Mr. Beshay because I have no idea if Kyro is a man or a woman. A quick web search didn’t provide an answer, nor any background of qualifications on UI design), blasted Microsoft’s “Metro” UI in Windows 8 of running against millions of years of evolution of how the human eye sees things. The biggest complaint in the blog post is that the “Metro” UI is flat and doesn’t distinguish between things you can click on and those you can’t. But take a look at Kyro’s own blog. See that logo at the top? Can you click on it or not?

I’m not saying Microsoft hit a home run with “Metro”. I have several issues with it, but I am not a designer. However, “Metro” in Windows 8 is an almost exact copy of “Metro” in Windows Phone that has won several design awards. My biggest complaint about Kyro’s post is what I pointed out above regarding the logo. Before you start complaining about something other people or companies do, take a look at yourself first.  Oh, and back it up with qualifications.


Microsoft Awards MVPs

Four times a year, Microsoft announces recipients for the Most Valuable Professional (MVP) award. The award goes to people who do not work for Microsoft, but support users by speaking at or organizing events, answering questions in forums, writing books, magazine articles, blog posts, etc. and other community activities. There are about 4000 MVPs worldwide, covering most every Microsoft product. The award is given for past performance over the last year.

I am honored to again be given this award. My first time was 1996, although it could have been sooner. The earliest documents I have are dated that year and Microsoft’s records don’t go back that far. I was originally awarded for FoxPro, then Visual FoxPro, and now for Visual C# and have received the award every year since that first year.

Thanks to the community for putting up with me at events and forums. It is an honor to again to be an MVP.

1 Comment more...

Entity Framework Code First: One-to-Many

In the first post of this series, I showed you the basics of using Entity Framework Code First with a single table. In this post, I’ll talk about dealing with one-to-many relationships. We’ll use the code from Part 1 as our starting point, but will create and populate the tables again.

The place to start is with the entities and the context.

namespace EFLab
{
    public class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string State { get; set; }
        public virtual List<Email> Emails { get; set; }
    }

    public class Email
    {
        public int Id { get; set; }
        public int PersonId { get; set; }
        public string EmailAddress { get; set; }
    }

    public class EFContext : DbContext
    {
        public DbSet<Person> People { get; set; }
        public DbSet<Email> Emails { get; set; }
    }
}

I’ve added a class called Email, that is used to store the email address for a person, or in this case, zero to n email addresses. Also, look at the new Emails property of the Person class. It’s a virtual property. By making it virtual, it will be lazy loaded, so the data won’t actually be read until it’s needed.

Now we need some code to populate the data. Here’s the first attempt:

static void Main(string[] args)
{
        EFContext context = new EFContext();
        Person person;
        Email email;

        person = new Person();
        person.FirstName = "Bullwinkle";
        person.LastName = "Moose";
        person.State = "MN";
        email = new Email { EmailAddress =
bullwinkle@frostbitefalls.com};
        person.Emails.Add(email);
        context.People.Add(person);
        context.SaveChanges();
   }

If you guess this would not work, you’re correct. It throws an exception on the line person.Emails.Add(email).

9-9-2012 7-07-31 PM

This is because List<Email> has not been instantiated. It’s currently null. Let’s fix it and add some additional data.

static void Main(string[] args)
{
        EFContext context = new EFContext();
        Person person;
        Email email;

        person = new Person();
        person.FirstName = "Bullwinkle";
        person.LastName = "Moose";
        person.State = "MN";
        person.Emails = new List<Email>();
        email = new Email { EmailAddress = "bullwinkle@frostbitefalls.com" };
        person.Emails.Add(email);
        context.People.Add(person);
        context.SaveChanges();

        person = new Person();
        person.FirstName = "Rocky";
        person.LastName = "Squirrel";
        person.State = "MN";
        person.Emails = new List<Email>();
        email = new Email { EmailAddress = "rocky@frostbitefalls.com" };
        person.Emails.Add(email);
        email = new Email { EmailAddress = "rocky@squirrel.com" };
        person.Emails.Add(email);
        context.People.Add(person);
        context.SaveChanges();

        person = new Person();
        person.FirstName = "Peter";
        person.LastName = "Peachfuzz";
        person.State = "NY";
        context.People.Add(person);
        context.SaveChanges();
}

When we look at the data for the People table, we see the correct values were added

9-9-2012 7-15-57 PM

But,what about the Emails table?

9-9-2012 7-16-37 PM

Whoa! Magic! Entity Framework correctly populated the PersonId value for us. This is because EF inferred the parent ID and populated the column.

But what about reading data back? Well, it’s not as easy as you may think. Let’s try it and see what we get.

static void Main(string[] args)
{
    EFContext context = new EFContext();
    var people = context.People;

    foreach (var person in people)
    {
        Console.WriteLine(person.FirstName);
        Console.WriteLine(person.LastName);
        foreach (var email in person.Emails)
        {
            Console.WriteLine(email.EmailAddress);
        }
        Console.WriteLine("==========");
    }
    Console.ReadLine();
}

If you try to run this, you’ll get a SystemData.EntityCommandExecutionException. Specifically, the error is “There is already an open DataReader associated with this Command which must be closed first.”. What’s happening, is you can’t read from both tables using the same EntityCommandDefinition.

There are a couple of ways to fix this. The first, is to add MultipleActiveResultSets=true to the connection string in app.config. This will allow you run the above code and get the email addresses without throwing the error.

The second way is to convert the query into a List before looping through it. Change the line that reads to data to var people = context.People.ToList(). This causes the data to be read in one go instead of two.

When it comes to delete, you’ll have to handle each table yourself. If you delete just the row from the People table, the related Emails will be orphaned.

In the next post in this series, we’ll look at many-to-many relationships.


Entity Framework Code First Basics

Entity Framework (EF) marked a big step forward for application developers, but early versions were met with complaints that many important features were missing. Many of those big issues were addressed in EF 2. And when Code First came along, pretty much all the big issues were gone.

This is part one in a series on EF Code First basics. I’ll cover working with a single table, one-to-one, one-to-many, and many-to-many relationships. The series came out of my needs to understand how to setup and work with EF. Just a heads-up. There is A LOT to EF that I won’t cover. I recommend Julia Lerman’s great book, “Programming Entity Framework Code First”.

To get started, I created Visual Studio Console project named EFLab. When I experiment with something, I always put Lab in the solution name. Next, I used NuGet to add EF to the project. Because I’m working with VS 2012, EF 5.0 was automatically selected for me. Now it’s time to create the entity. To make things easy for the example, I created a single .cs file called Entities. But, I renamed the class. I intend to put all the code needed to make EF work inside this class.

using System.Data.Entity;

namespace EFLab
{
    public class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

    public class EFContext : DbContext
    {
        public DbSet<Person> People { get; set; }
    }
}

There are two classes here. The first, Person, defines the entity and maps to the actual table in the database. Note that at this point, the database does not exist. We’re using Code First, which will create the database for us.

The second class, EFContext, inherits from DbContext that is defined in System.Data.Entity. This class allows us to work with the database and will provide all the CRUD code. Let’s now see how to insert a new row into the table. Here’s the code from Main().

static void Main(string[] args)
{
       EFContext context = new EFContext();

        Person person = new Person();
        person.FirstName = "Bullwinkle";
        person.LastName = "Moose";

        context.People.Add(person);
        context.SaveChanges();
}

First, we get an instance of the context object, then create and populate the Person object and finally add the person to the People collection and save the changes. But, we’re not quite ready to run the code yet. We need to setup the database connection. Here’s the entry from app.config.

<connectionStrings>
  <add name="EFContext" providerName="System.Data.SqlClient"
       connectionString="Server=(local);Database=EFLab;Integrated Security=True;"/>
</connectionStrings>

Note the name of the connection, EFContext. This is the same name as our context object. If these two match EF will automatically wire everything up for us. Now it’s time to run the code. Remember, we haven’t done anything with SQL Server.

After the console screen closes, it’s time to look at SQL Server to see what happened. I created a new data connection in the Server Explorer in Visual Studio. The first thing you notice is that EF has created a new database named EFLab, as specified in the connection string. Drilling down further, you see that a table named People was created. Where did this name come from? It has nothing to do with the context. EF has pluralizing rules built in. Usually, it just adds an s to the name of the entity, but it also understands how to do things like add “es” for pluralization and that Person should not be Persons, but rather People. Right-click on the table and select “Show Table Definition”.

9-9-2012 1-00-13 PM

Each property of the entity has been used to create a column in the table. EF will recognize things like Id or PersonId to be the key field and automatically make it an identity and primary key column. But what about the data? Again, right-click on People in the Server Explorer, but this time select Show Table Data.

9-9-2012 1-07-06 PM

Entity Framework inserted the data, just as we asked.

Now, we have some additional questions. If we run the code again, will the database and table be recreated or will the new row simply be added to the existing table? What about Read, Update, Delete? What happens when you change the schema? Let’s find out!

First, let’s just rerun the code, then look at the table data again. We find that there are now two entries for Bullwinkle Moose, each with a different Id. So, the first question is answered. Entity Framework just adds the record without recreating the database. It also tells us that if we create the entities for an existing database, EF will just use what’s there.

Now, let’s read, edit, then save. We have two entries for Bullwinkle Moose. Let’s edit the second one to be Rocky Squirrel. We can use the id to find the row in the table. Here’s the modified code from Main().

static void Main(string[] args)
{
        EFContext context = new EFContext();

        Person person = new Person();
        person.FirstName = "Bullwinkle";
        person.LastName = "Moose";
        context.People.Add(person);
        context.SaveChanges();

        Person editPerson = context.People.Find(2);
        editPerson.FirstName = "Rocky";
        editPerson.LastName = "Squirrel";
        context.SaveChanges();
}

When you look at the data afterwards, you’ll see the changes

9-9-2012 1-20-36 PM

The requested row has been changed and because the insert code is still run, another Bullwinkle Moose row was added. Let’s delete that one, but we don’t want to add another row, so comment out or delete the insert, and edit code.

static void Main(string[] args)
{
    EFContext context = new EFContext();

    Person deletePerson = context.People.Find(3);
    context.People.Remove(deletePerson);
    context.SaveChanges();
}

Run this code and the row will be deleted. But before we modify the schema, let’s see how to read data if you don’t know the Id of the row. There are a couple of good ways to do this. Before we look at them, let’s see some things that you may be tempted to try, but don’t work.

Person person1 = context.People.Find(p => p.FirstName == "Bullwinkle");
Person person2 = context.People.Where(p => p.FirstName == "Bullwinkle");
Person person3 = context.People.FirstOrDefault(p => p.FirstName == "Rocky");

The first one won’t work because Find takes an ID, not a lambda expression. The next two won’t work for two reasons. First, People is a collection and the code specifies returning a Person. Even if you change it to List<Person> it won’t work for the second reason.. it’s a LINQ expression. Let’s look at a couple of options that will work

var people1 = context.People.Where(p => p.FirstName == "Bullwinkle");
var people2 = context.People.FirstOrDefault(p => p.FirstName == "Rocky");

Now we’ll get back something that will work. But it still isn’t a Person object. You can add .ToList() to the end of the right-hand side of the line and have a ready-made, populated list.

So, we’ve seen how to create a database, insert, read, update, and delete data. But what about schema changes? How are they handled. Let’s start with changing the schema in the code. We’ll simply add a new column to the entity.

public class Person
{
       public int Id { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
       public string State { get; set; }
}

and modify Main() to insert a new row.

static void Main(string[] args)
{
        EFContext context = new EFContext();

        Person person = new Person();
        person.FirstName = "Peter";
        person.LastName = "Peachfuzz";
        person.State =
"MN";
        context.People.Add(person);
        context.SaveChanges();
}

When you run the code, you get an exception.

9-9-2012 1-49-22 PM

Code First Migrations is new to EF 5 and is explained clearly in the MSDN documentation. But there is another way to deal with this. You can make the change manually. So, not only will you need to add the table to the entity, you’ll have to manually add it to the table too. But, you have to do one other thing. Delete the file that EF uses to track the schema.

Open SQL Server Management Studio (SSMS) and drill down into EFLab and then Tables. You’ll see the table, dbo.__MigrationHistory under System Tables.

9-9-2012 2-04-46 PM

System Tables don’t show up in Visual Studio, which is why you need to use SSMS. Delete the file. Once you’ve made the manual changes, you can run your program and Peter Peachfuzz will be inserted.

Remember that I mentioned that EF uses Id or TableId as the key field. But what if you have an existing table that doesn’t follow these rules? The solution is to add an attribute to the key field. So, it would change our model.

public class Person 

    [Key]
    public int Identifier { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
}

If you have a compound key, you must specify each column, and the order it appears in the key.

public class Person 

    [Key]
    [Column(Order = 0)]
    public string FirstName { get; set; } 
   
    [Key]
    [Column(Order = 1)]
    public string LastName { get; set; } 
}

 

So, there you have it, the basics of working with Entity Framework. In part two of this series, we’ll look at one-to-many relationships.


Building MVC4 Projects on a Build Server

It’s clear that Microsoft wants all of us to use TFS. The reality is, that won’t happen. Using a build server other than TFS adds some complications that just simply shouldn’t exist. I spent over three hours today working through the various issues of my first MVC4 project. Allow me to regurgitate the issues and fixes so that you may be better prepared and have fewer issues.

Step 1: Install the .Net 4.5 Runtimes. This is easy via a download from the Microsoft web site.

Step 2: Install the Team City upgrade that supports .Net 4.5. Again, easy through a link on the JetBrains web site.

Step 3: Create Team City project. Check.

Step 4: Click Run. Uhoh. Lots of errors.

The first one to tackle is a missing reference to System.Web.Mvc. How can that not be found? I installed the .Net Framework. Well…it’s actually not part of the framework. I then tweeted, “First .Net 4.5 build fails on build server. Looks like some .Net assemblies are missing.”. Peter Ritchie replied with a link to a blog post from Marc Gravel. The comments in that post suggest to copy the files from your local install to the build server. I that, then reran the build. Still missing references to System.Web.Mvc.

I jumped up to the Asp.Net web site to grab the install, but group security policies prohibited the Web Platform Installer from running on the server. I did a web search for “download MVC4″ and found this link to get it. I downloaded that, installed it on the build server and reran the build. System.Web.Mvc was found. I got past that error, but now a new one saying that a build task was missing for the database project.

Ugh. Why, oh why, can’t Microsoft have a single download with everything you need for a non-TFS build server? More web searching yielded this post on what you need and links to download everything. OK, more grumbling about Microsoft not including everything needed. I get the files and following the instructions on the link. Except that I can’t do step 5. The folder doesn’t exist. Let’s try it anyway. I run the build and the database errors are gone. But now there are new ones about missing the AutoMapper assembly.

The AutoMapper DLL is sitting in the bin folder on my local drive. It makes sense that the DLL is missing. The entre bin folder is ignored and not pushed to the Git server. What if there are other assemblies in that same folder that I need? So, I fire-up Visual Studio and do a Build -> Clean. Sure enough, there are a few assemblies that are still there then tweet a gripe about this. Paul Stack if I was using bindeployable assemblies. No, I’m not. IMO, it shouldn’t be my responsibility to do this, except with my own internal assemblies. If I NuGet a package (looking at you, AutoMapper), it should install into the bindeployable folder of the project.

I copy the assemblies from my local bin folder to the build server and rerun the build. And…it works. I finally have the build running on the build server. Total time over three hours to get this project running.

What’s the solution to all this? First, Microsoft should have a single download package that includes EVERYTHING needed to build a project on the build server. By this, I mean all the Microsoft assemblies, including MVC and database projects. Short of this, provide a SINGLE page that can be EASILY found that lists what you’ll need and links to download it.

Second, NuGet pacakges should get deployed to the bindeployable folder, not just the bin folder. This way, you can easily check them in to your version control system.

 

1 Comment more...

Copyright © 1996-2010 Developer.Blog();. All rights reserved.
iDream theme by Templates Next | Powered by WordPress