Skip to main content

Posts

Showing posts from February, 2013

Fluent NHibernate .. Or as my manager calls it "Shibernate" (Tutorial 1)

So this is a first of a few posts I will be doing on a simple NHibernate application. This post is pretty basic but in my subsequent posts, I'll be adding more functionality and/or modifying components to include dependency injection using Microsoft Unity.

The base project is a minute modification of https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started.

So here we go ...

1. Create a new Solution called "Project".

2. To it, add a class library called "Project.Domain". As the name suggests, this will represent your domain entities.


3. Create the Employee, Product and store Classes. I usually like to separate the Properties in partial classes.


public class Employee
{
public virtual int Id { get; protected set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual Store Store { get; set; }
}

public class Product
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }

Problem with delegate within foreach

The picture shown below represents my data. Data that I have and the expected result at the end:




The logic being, that for every date in the list of dates, find the associated price tuple where the effective date is less than or equal to the date and is the max date.

The structure of Price is shown below.


public class Price
{
public int PriceId { get; set; }

public DateTime EffectiveDate { get; set; }

public double PriceAmount { get; set; }

public DateTime CreatedOn { get; set; }
}

I have a static method that gets me the data that I need

static List<Price> GetPrices()
{
return new List<Price>()
{
new Price()
{
PriceId = 1, EffectiveDate = new DateTime(2012,1,1),
PriceAmount = 100, CreatedOn = new DateTime(2012,1,1)
},
new Price()
{
PriceId = 2, EffectiveDate = new DateTime(2012,1,1),
PriceAmount = 200, CreatedOn = new DateTime(2012,1,1)
},
new Price()
{