Independent
Independent

Reputation: 2987

Insert/Update/Delete of EF in Business layer

I can't live with the idea that we need to recreate the insert/update/delete functionality in ALL pocos/bl objects? EF and linq2sql that have this so nice built in by itself.

How do you guys solve this on a effective way? Using a base class or some magic in the IQueryable pocos?

.NET 4

Upvotes: 0

Views: 395

Answers (1)

Vincent Vancalbergh
Vincent Vancalbergh

Reputation: 3337

Since your Entity Framework / Linq objects are probably inherited from some base class you can inherit the objects in your business layer from a single base class. Then do something like this:

public class BusinessBaseCollection
{
    protected EFBaseCollection _efObject = null;

    public BusinessBaseCollection(EFBaseCollection efObject)
    {
        _efObject = efObject;
    }

    public Add(BusinessBase obj)
    {
        _efObject.Add(obj);
    }

    //Add other CRUD stuff here
}

Upvotes: 1

Related Questions