Best Practices Question

Posted on 2009-12-16
Last Modified: 2013-11-11
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.
Question by:rock815
    LVL 18

    Accepted Solution

    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.

    LVL 1

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now