- northwind.zip
- Castle.ActiveRecord.dll
- Castle.Core.dll
- Iesi.Collections.dll
- log4net.dll
- NHibernate.dll
- NMock2.dll
- Northwind.DataAccess.Test
- Northwind.DataAccess
- Northwind.Domain.Test
- Northwind.Domain
- Northwind.Presentation.Test
- Northwind.Presentation
- Northwind.Services.Test
- Northwind.Services
- NorthWind.sln
- Northwind.TransferObjects.Test
- Northwind.TransferObjects
- Northwind.UI.Controls
- Northwind.UI
- nunit.framework.dll
|
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Queries;
using NHibernate;
using Northwind.DataAccess.Query;
using Northwind.Domain.Model;
using System;
using System.Collections.Generic;
using System.Text;
namespace Northwind.DataAccess.Repository
{
public class InMemoryCustomerRepository : InMemoryRepositoryBase<Customer, string>, IInMemoryCustomerRepository
{
protected static string lastId;
protected override object GetNextID()
{
return null;
}
public Customer[] FetchByName(string name)
{
FetchCustomerByNameQuery fbn = new FetchCustomerByNameQuery(name);
Customer[] domainObjects = (Customer[])ActiveRecordBase.ExecuteQuery(fbn);
return domainObjects;
}
public Customer[] FetchByNameRange(string lowerBoundName, string upperBoundName)
{
FetchCustomerByNameRangeQuery fbnr = new FetchCustomerByNameRangeQuery(lowerBoundName, upperBoundName);
Customer[] domainObjects = (Customer[])ActiveRecordBase.ExecuteQuery(fbnr);
return domainObjects;
}
protected override void LoadChildren(Customer customer)
{
OrderRepository orderRepository = new OrderRepository();
Order orderExample = new Order();
orderExample.CustomerID = customer.ID;
Order[] orders = orderRepository.FetchByExample(orderExample);
foreach (Order order in orders)
{
order.IsNew = false;
order.IsDirty = false;
customer.Orders.Add(order);
}
}
protected override void AddOrUpdateChildren(ISession session, Customer customer)
{
InMemoryOrderRepository inMemoryOrderRepository = new InMemoryOrderRepository();
foreach (Order order in customer.Orders)
{
inMemoryOrderRepository.AddOrUpdate(session, order);
}
}
protected override void RemoveChildren(ISession session, Customer customer)
{
InMemoryOrderRepository inMemoryOrderRepository = new InMemoryOrderRepository();
LoadChildren(customer);
foreach (Order order in customer.Orders)
{
inMemoryOrderRepository.Remove(session, order);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.