The McDev Blog

Kevin McKelvin's perspective of the Ruby world.

The NH3 Music Store Part 2

So my IMusicStoreContext is in place on all of the controllers now. I still need to actually write an implementation of IMusicStoreContext, but that can come later.

My next goal is to get all of the entity properties into my POCOs. The NHibernate way has typically been to pass instances of the object around instead of foreign key integers.

Using MVC means that I will at least need the primary key to be a part of my entity.

For example http://localhost/albums/1 must point to the album with id 1, so I’m going to need to keep my Id available to me in code. This is a design decision that’s important with NHibernate that isn’t possible with EF4.

Here’s the domain model I’ve come up with so far. This might change at some stage in the future. I had to add OrderDetail.

Notice that instead of passing around integer Id’s, I’m referencing the related types directly. For example – Genre on the Album class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class Album
{
    public virtual int AlbumId { get; set;}
    public virtual Genre Genre { get; set;}
    public virtual Artist Artist { get; set; }
    public virtual string Title { get; set; }
    public virtual decimal Price { get; set; }
    public virtual string AlbumArtUrl { get; set; }
}

public class Artist
{
    public virtual int ArtistId { get; set; }
    public virtual string Name { get; set; }
}

public class Cart
{
    public virtual int RecordId { get; set; }
    public virtual string CartId { get; set; }
    public virtual Album Album { get; set; }
    public virtual int Count { get; set; }
    public virtual DateTime DateCreated { get; set; }
}

public class Genre
{
    public virtual int GenreId { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }
}

public class Order
{
    public virtual int OrderId { get; set; }
    public virtual DateTime OrderDate { get; set; }
    public virtual string Username { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual string Address { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string PostalCode { get; set; }
    public virtual string Country { get; set; }
    public virtual string Phone { get; set; }
    public virtual string Email { get; set; }
    public virtual string Total { get; set; }

    public virtual ICollection<OrderDetail> OrderDetails { get; set; }
}

public class OrderDetail
{
    public virtual int OrderDetailId { get; set; }
    public virtual Order Order { get; set; }
    public virtual Album Album { get; set; }
    public virtual int Quantity { get; set; }
    public virtual decimal UnitPrice { get; set; }
}

After all of this I’m down to 26 compiler errors. Yay!