…and more…
Continuing my EF4 progress series:
Part 1
Part 2
here is now my latest version. What’s new in it? Well basically a lot. Starting with the GUI and functionality I have now crud for orders as well as orderrows. And I have added a new entity into my model, namely product. So you basically start off with searching all orders with one or more orderrows containg the product you selected in the combobox:

We also have some ugly order/orderrow editing screens:


In the download you will find the complete VS2010 solution:

And the parts I am at least somewhat proud of are
Generic repositories
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace Systementor.Database.Repositories
{
public interface IRepository<t> where T : class
{
void Insert(T item);
void Update(T item);
void Delete(T item);
T Get(Expression<func<t, bool>> whereclause);
T Get(Systementor.LinqHelper.Specification.ISpecification<t> spec);
int Count(Expression<func<t, bool>> whereclause);
int Count(Systementor.LinqHelper.Specification.ISpecification<t> spec);
IList<t> GetAll();
IList<t> GetAll<t2>(Expression<func<t, T2>> orderbyexpr, int nStartAt = -1, int NumToSel = -1);
IList<t> Find(Systementor.LinqHelper.Specification.ISpecification<t> spec);
IList<t> Find(Expression<func<t, bool>> whereclause);
IList<t> Find<t2>(Expression<func<t, bool>> whereclause, Expression<func<t, T2>> orderbyexpr, int nStartAt = -1, int NumToSel = -1);
IList<t> Find<t2>(Systementor.LinqHelper.Specification.ISpecification<t> spec, Expression<func<t, T2>> orderbyexpr, int nStartAt = -1, int NumToSel = -1);
}
I have also implemented the specification pattern where queries (where part that is) are handled like
Systementor.Database.Repositories.IRepository<order.Domain.PurchaseOrderHeader> rep = uow.CreateRepository<order.Domain.PurchaseOrderHeader>();
IList<order.Domain.PurchaseOrderHeader> l = rep.Find(Order.Domain.PurchaseOrderHeader.Spec_OrdersContainingProduct(nSelid))
I.e the business layer code Order.Domain.PurchaseOrderHeader – serves the where specifications possible.
ORM abstraction
look in Systementor.Database.Repositories.IDataContext and the like. I will try to plug NHibernate in soon instead of EF4.
UnitOfWork and EF4 tracing
I have wrapped the EFWrapperToolkit tracing (???) and am able to publish single events for each query – instead of two (commandstarting,commandexecuted)
The eventarguments you (caller) get is
public class EFTracingEventArgs
{
public int CommandId;
public DateTime dtStarted = new DateTime(1900,1,1);
public DateTime dtFinished = new DateTime(1900, 1, 1);
public System.Data.IDbCommand Command;
public enum StatusEnum
{
Executing,
Finished,
Failed
}
public StatusEnum Status;
Download zip file
Be sure to modify the connectionstring in app.config for GUI
Where to go from here? I was gonna add validation, but soon discovered I better go the full way here and do DTOs instead of sending the entities to the client. So I will do that and add (gui) validation to those. But before that I really need to work on the model. I will simply try to go the DDD route here, I know its a lot easier to go the other way around, here I sit with an existing database – anemic model/no domain expert to tell me, but I’ll fake some requirements and do my best.
My guess is that will render some new Entity Framework 4 problems – I mean I do like having my POCOS autogenerated to start with, but FixupCollection/public setters etc, while extremly convinient, should actually be a no/no in any sane OO aproach, DDD or not.