none
Designing Layer Application Using LINQ (Linq to Sql Classes dbml) RRS feed

  • Question

  • I plan to use Linq to Sql Classes in a Three tier architecture. for that I need some Idea where to use the Dbml file in DAL?
    Please make me clear.

    Thanking you
    Selvakumar Rathinam
    • Moved by YiChun Chen Monday, September 21, 2009 9:08 AM LINQ to SQL issue (From:.NET Framework Setup)
    Friday, September 18, 2009 10:17 AM

Answers

  • Hi Selvakumar Rathinam,

     

    If you are using the architecture like this:


     


    I would suggest that you use customize classes to map the tables. You can put it in Model module which could be part of BLL or aside.

    Then, you can put all the LINQ statements in DAL.

     

    Sample for customize class:


    [Table(Name = “Customers”)]
    
    public class Customer
    
    {
    
    [Column(IsPrimaryKey = true)]
    
    public string CustomerID { get; set; }
    
    [Column]
    
    public string CompanyName { get; set; }
    
    [Column]
    
    public string ContactName { get; set; }
    
    [Column]
    
    public string ContactTitle { get; set; }
    
    [Column]
    
    }
    


     

    Connect and query with the customize class:

     

    static void Main()
    
    {
    
    DataContext dc = new DataContext(@”Data Source=.\SQLEXPRESS;
    
    AttachDbFilename=|DataDirectory|\NORTHWND.MDF;
    
    Integrated Security=True;User Instance=True”);
    
    dc.Log = Console.Out; // Used for outputting the SQL used
    
    Table < Customer > myCustomers = dc.GetTable < Customer > ();
    
    foreach (Customer item in myCustomers)
    
    {
    
    Console.WriteLine(“{0} | {1}”,
    
    item.CompanyName, item.Country);
    
    }
    
    Console.ReadLine();
    
    }
    

     

     

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Friday, September 25, 2009 1:52 AM
    Tuesday, September 22, 2009 8:22 AM

All replies

  • Hi Selvakumar,

    I am moving this thread from Base ".Net Framework Setup" forum to the "LINQ to SQL" forum, since the issue is related to LINQ to SQL. There are more experts in the "LINQ to SQL" forum.

    Thanks
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 21, 2009 9:07 AM
  • Hi Selvakumar Rathinam,

     

    If you are using the architecture like this:


     


    I would suggest that you use customize classes to map the tables. You can put it in Model module which could be part of BLL or aside.

    Then, you can put all the LINQ statements in DAL.

     

    Sample for customize class:


    [Table(Name = “Customers”)]
    
    public class Customer
    
    {
    
    [Column(IsPrimaryKey = true)]
    
    public string CustomerID { get; set; }
    
    [Column]
    
    public string CompanyName { get; set; }
    
    [Column]
    
    public string ContactName { get; set; }
    
    [Column]
    
    public string ContactTitle { get; set; }
    
    [Column]
    
    }
    


     

    Connect and query with the customize class:

     

    static void Main()
    
    {
    
    DataContext dc = new DataContext(@”Data Source=.\SQLEXPRESS;
    
    AttachDbFilename=|DataDirectory|\NORTHWND.MDF;
    
    Integrated Security=True;User Instance=True”);
    
    dc.Log = Console.Out; // Used for outputting the SQL used
    
    Table < Customer > myCustomers = dc.GetTable < Customer > ();
    
    foreach (Customer item in myCustomers)
    
    {
    
    Console.WriteLine(“{0} | {1}”,
    
    item.CompanyName, item.Country);
    
    }
    
    Console.ReadLine();
    
    }
    

     

     

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Friday, September 25, 2009 1:52 AM
    Tuesday, September 22, 2009 8:22 AM