views:

26

answers:

1

Hi.

I'm developing a project using a layered architecture. I have a DAL in which i'm using Entity Framework, a business logic layer which consumes the objects returned by the DAL and an app layer.

I'm not entirely sure i'm thinking this right, so i'll just ask you what you think.

My DAL is based on mappers. I have types - mappers - that the BLL uses to operate on my data. These mappers return DTO's, because i did not want to expose to my BLL any EF objects so their implementations are not dependent on EF to work.

All these mappers do are CRUD actions on a single 'table', like:

using (var contex = new EFEntities()){
  var obj = (from x in context.Table where x.ID == param select x).SingleOrDefault;
  return Map(x.ToList());
}

The Map method maps the EF object to a DTO, which has only some properties to map the values i want to expose.

Is there a more elegant approach to this? I am just using EF to facilitate the access to my database - i don't have to write any ADO.NET code.

Any input on this would be welcome.

Thanks.

A: 

I have a DAL in which i'm using Entity Framework, a business logic layer which consumes the objects returned by the DAL and an app layer.

That is a perversion, given taht y ouare putting a complet object layer into your dal. EF is a lot more than a DAL.

a business logic layer which consumes the objects returned by the DAL and an app layer.

The term you may want to look up for that is "anemic object model", and it is not a nice term.

Is there a more elegant approach to this?

Don#t fight EF. if you dont like it, don't use it - there are a LOT better frameworks around.

TomTom
But i like how EF works. Maybe i don't fully understand it, but i like it. Btw i meant that my DAL uses EF to access data. But i restrict EF to my DAL, other layers are given DTOs by the DAL.
Alka
You dont understand anything about OO it seems - this is, as I said, a perversion of a what EF can do.
TomTom
What's the right way to use it?
Alka
Use it as business object layer. As per documentation and standard approach for O/R mappers in the last 20 years since they were invented. If you dont know how to program with objects, I suggest Forlwer's excellent "Building Object Applications That Work".
TomTom
Basically: you dont need a DAL becasue you already have one - IN EF INTERNALLY. EF Objects ARE objects, thus they are what is normally called business objects.
TomTom
Now that was a bit more useful. I know that EF serves as a DAL, i was merely mapping it to my DTOs that were to be used in the top layers. I had bll in a separate layer though. I guess that's what's called anemic object model?
Alka
Yes. It is anemic because you strop out all from the obejcts that normally makes then objects. Read your Fowler
TomTom

related questions