views:

272

answers:

2

HI all

I was trying to follow the POCO Template walkthrough . And now I am having problems using it in n-tiers design.

By following the article, I put my edmx model, and the template generated context.tt in my DAL project, and moved the generated model.tt entity classes to my Business Logic layer (BLL) project.

By doing this, I could use those entities inside my BLL without referencing the DAL, I guess that is the idea of PI; without knowing anything about the data source.

Now, I want to extend the entities (inside the model.tt) to perform some CUD action in the BLL project,so I added a new partial class same name as the one generated from template,

public partial class Company
{
    public static IEnumerable<Company> AllCompanies()
    {
        using(var context = new Entities()){

            var q = from p in context.Companies
                    select p;

            return q.ToList();
       }
    }
}

however visual studio won't let me do that, and I think it was because the context.tt is in the DAL project, and the BLL project could not add a reference to the DAL project as DAL has already reference to the BLL.

So I tried to added this class to the DAL and it compiled, but intelisense won't show up the BLL.Company.AllCompanies() in my web service method from my webservice project which has reference to my BLL project.

What should I do now? I want to add CUD methods to the template generated entities in my BLL project, and call them in my web services from another project.

I have been looking for this answer a few days already, and I really need some guides from here please.

Bryan

A: 

I don't think DAL should have a reference to BLL. I think it should be vice versa. BLL should be persistence ignorant.

Kamyar
+1  A: 

Mhhh, your layer architecture looks a bit like a spaghetti plate. First in my opinion your POCO objects should be put in a different assembly which have no reference to any DAL, or else why bother about POCO ? Second, static method in partial class don't look good, keep your poco objects very simple, and surrender the logic of it to repositories.

Take a look at that and all will be crystal clear:

http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-1-model-and-poco-classes/

Roubachof