• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

Best Practices Question

This is more of a question of coding standards.

I'm fairly new to LINQ and have done my first project.  But maybe I'm doing this wrong?

I have 3 projects

1) Web (References the BR project)
2) Business Rules (BR)
3) Data (Basically ONLY the LINQ DBML)

My BR Project is where I do all the methods AddUser, EditUser, etc...

Is this the proper practice?

The problem I'm running into is my BR Adduser takes the param from LINQ Proj.  So BR.AddUser(LINQ.User).  When I call this from the Web project it doesn't have the intellisense unless I reference the LINQ proj too.

Should the BR and LINQ projects be combined?  
Or would I make an object in the BR to handle the LINQ entity so that it works with the Web intellisense?  

Like so:

public class BRUser
    public string Username;
   public string Password;
  public string Name;

And convert BR.Adduser(LINQ.User) to BR.AddUser(BRUser u)

Please advise.  Thanks for your help.
1 Solution
Richard LeeSoftware EnthusiastCommented:
The ideal situation when working with N-Tier architectures is that each tier handles its own responsibilities and does not know the internal working of the other tiers/layers.

Presentation - Handles all UI interaction and uses BL
Business Layer - Performs all business rules and uses the DL for data operations
Data Layer - Performs on data operation such as CRUD (Create, Read, Update, Delete). No business logic, e.g. check for null, check if ID > 0, etc.

Now the ideal solution for that problem is to use Data Transfer Objects. When using DTO's however you lose some of the LINQ functionality when tracking objects. The data access layer will accept and return DTOs therefore no need to expose the DataContext of the data layer to the business layer. Of course your DTO which will normally match you LINQ object will reside in a separate project so that both the DataLayer and the Business Layer can reference these project without getting a circular reference issue.

Saying this if you don't want the work of using DTOs then you can simply put the DBML file in the separate project therefore both the Business and Data Layer has access to it.

I would go for DTOs as you train of thought was taking you already with the BRUser suggestiong. However I would not specialise the name with the BR as you may sometimes want to pass these Objects back to your presentation layer and vice versa.

rock815Author Commented:
Thank you for the advice.  I'll look into how to implement DTOs and go from there.  Much appreciated!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now