none
Linq to SQL - Object class

    Question

  • I am trying to build a 3 tier L2S model. Is the following approach correct?

    namespace MyProduct.DAL: The DAL has the L2S autogenerated class and DBML file.

    namespace MyProductBLL: The BLL has the methods that connect to the above DAL using the DataContext.

    Is that valid?

    Also, my confusion comes in that in order to access the USER object in the presentation layer, I still have to the reference the DAL. Doesn't this break the 3-tier approach whereby the Presentation layer should only talk to the BLL?

    Thanks



    You are so wise...like a miniature budha covered in fur. -Anchorman

    Saturday, October 19, 2013 1:05 AM

Answers

  • <copied>

    Also, my confusion comes in that in order to access the USER object in the presentation layer, I still have to the reference the DAL. Doesn't this break the 3-tier approach whereby the Presentation layer should only talk to the BLL

    <end>

    1) You should just call it BLL and DAL.

    2) You should be using DTO(s) Data Transfer Objects.

    http://en.wikipedia.org/wiki/Data_transfer_object

    You can make a classlib project call it DTOS if you like. It will contain the DTO(s). You will map Linq-2-SQL class data properties to DTO class properties. And you will map DTO back to Linq-2-SQL class and persist Linq-2-SQL class to the database. All projects will have reference to the DTOS project. The DTO(s) are what you would be sending through the tiers, leaving the Linq-2-SQL-classes/objects at the DAL.

    The presentation layer should have no reference to the DAL.

    Your DTO looks like this.

        public class DTOArticle
        {
            public int ArticleID { get; set; }
            public string Tille { get; set; }
            public string Body { get; set; }
            public int? AuthorID { get; set; }
        }

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    So you send a DTO or DTO(s) in a collection through the tiers.

    Sunday, October 20, 2013 7:16 AM

All replies

  • Hello:

    I think you can just put your model classes inside another new Class library called model, and then create DAL and BLL and refer the model Class Library. Then refer the 4 things directly into your project.


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    Saturday, October 19, 2013 1:15 AM
  • Hi Reza,

    Try this link to do simple 3 tier architecture....

    3-tier architechure Sample

    Saturday, October 19, 2013 5:58 AM
  • Krish,

    The question I am asking is pertaining to Linq2Sql, it is different to a SqlConnection model because the classes are generated automatically in the DBML. The link you referred is not related to L2S.


    You are so wise...like a miniature budha covered in fur. -Anchorman

    Saturday, October 19, 2013 7:38 PM
  • I guess my question is how do I put the model classes into a seperate class since the L2S class autogenerates the model class for the DBML.


    You are so wise...like a miniature budha covered in fur. -Anchorman

    Saturday, October 19, 2013 7:39 PM
  • <copied>

    Also, my confusion comes in that in order to access the USER object in the presentation layer, I still have to the reference the DAL. Doesn't this break the 3-tier approach whereby the Presentation layer should only talk to the BLL

    <end>

    1) You should just call it BLL and DAL.

    2) You should be using DTO(s) Data Transfer Objects.

    http://en.wikipedia.org/wiki/Data_transfer_object

    You can make a classlib project call it DTOS if you like. It will contain the DTO(s). You will map Linq-2-SQL class data properties to DTO class properties. And you will map DTO back to Linq-2-SQL class and persist Linq-2-SQL class to the database. All projects will have reference to the DTOS project. The DTO(s) are what you would be sending through the tiers, leaving the Linq-2-SQL-classes/objects at the DAL.

    The presentation layer should have no reference to the DAL.

    Your DTO looks like this.

        public class DTOArticle
        {
            public int ArticleID { get; set; }
            public string Tille { get; set; }
            public string Body { get; set; }
            public int? AuthorID { get; set; }
        }

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    So you send a DTO or DTO(s) in a collection through the tiers.

    Sunday, October 20, 2013 7:16 AM
  • Hi Reza,

    Thanks for your posting.

    From your description,  this issue is related  to Linq to SQL, I think that Linq to SQL forum is more suitable for it .So I move it to Linq to SQL forum .

    Hope these help.


    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 22, 2013 3:18 AM