title: Entity Framework 4.1 and Business Logic Layer
body: <p>I am trying to use Entity Framework 4.0 for an asp .net application. As of now, it will be old style code behind files and without unit testing but in the future I may use MVP and unit testing but as of now, it is not a concern for me. I am using Database First approach. Here is a model ( I could not post image as I need reputation to post image)</p>
  
  <ul>
  <li>Table: Application (ApplicationID, Name, Hidden) </li>
  <li>Table: User (UserID, ApplicationID, Username, IsActive) </li>
  <li>Table: Role (RoleID, ApplicationID, Name) </li>
  <li>Table: UserRole (UserRoleID, RoleID, UserID)</li>
  </ul>
  
  <p>I have been reading a lot about Entity Framework and how to use it but still could not get a very basic idea about some stuff. Where do I write a code like this for Application, User, Role, UserRole etc?</p>
  
  <pre><code>public List&lt;Application&gt; GetAllUnhiddenApplications()
  {
      List&lt;Application&gt; applist = null;
      using (CustomAppsPortalEntities ctx = new CustomAppsPortalEntities())
      {
          applist = (from app in ctx.Applications
              where app.Hidden == false
              orderby app.Name
              select app).ToList();
      }
      return applist;
  }
  </code></pre>
  
  <p>I have separated Context and Entities in separate projects Project.Data and Project.Entities respectively. My question is if above code belongs to BLL (class name ApplicationBLL) or DLL (ApplicationDLL)? From past 2 days, I have been searching lots of SO questions, blogs, tutorials and different people have different approach. Here is my dilemma.</p>
  
  <p>If I put the code in Data layer, then in the business layer, I have to create a "pass through" function like ApplicationBLL.GetAllUnhiddenApplications which will return ApplidationDLL.GetAllUnhiddenApplications. I have to repeat it for all the queries and basically whole BLL will eventually become "pass through" layer for DLL. Can you give me a concrete example of what Business layer will be used for in reference to above schema?</p>
  
  <p>If I put the code in Business layer, then linq will exist in Business layer which eventually will be converted to SQL by Entity Framework so it is like exposing query logic to Business Layer.</p>
  
  <p><strong>Our Environment</strong>
  Our environment is fast paced and want to complete this project as soon as possible with the moderately proper approach where there is a separate layer but in the future when we find time, we may refactor the code and make it really robust but it is not a concern as of now but if the time permits, we want to implement best practices right now versus refactoring code in the future. </p>