none
Pharyns class for ADO.net and LINQ RRS feed

  • Question

  • Hi all.
    We use a class as Pharyns class for ADO.net. All queries goes across from methods of this class calles BaseClass.
    For example when we want to fill a DataTable, we use from ReqListInfoByDataTable() :
    An example method in BaseClass:
    public bool ReqListInfoByDataTable(DataTable dt, string strQuery)
      {
       try
       {
        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strQuery, SqlCnnRO);
        OpenDbConnectionRO();
        sqlDataAdapter.SelectCommand.CommandTimeout = 500;
        sqlDataAdapter.Fill(dt);
        return true;
       }
       catch (Exception err)
       {
        SqlException sqlExp = (SqlException)err;
        SqlExeptionNumber = sqlExp.Number; 
        ErrMessage = GetExceptionMessage(err);
        WriteErrorLog(strQuery, err.Message);
        return false;
       }
       finally
       {
        CloseDbConnectionRO();
       }
      }
    
    In application:
    DataTable dt = new DataTable();
      SearchCurrentLaptopAccessories(dt);
    
    
    public bool SearchCurrentLaptopAccessories(DataTable dt)
      {
       dt.Clear();
       string str = "select * from tb_LaptopAccessories where LaptopID=" + AutoIDLaptop + "";
       if (baseClass.ReqListInfoByDataTable(dt, str))
        return true;
       else
       {
        ErrMessage = baseClass.ErrMessage;
        return false;
       }
      }
    
    BaseClass is a layer between business and data base layer.
    So with this class we can manage all queries and SP executing.
    For example we can find all IP address of people that exacute a certain query in web applications.

    Now we want to use LINQ instead of ADO.net and by the way we want that retain a class similar to BaseClass.
    Can we create this?
    Please give me sample code for application and BaseClass.

    Each problem has a solution.
    Sunday, November 14, 2010 5:58 AM

Answers

  • Ok, 

    Logging IP addresses does not have anything to do with data access; it should be a separate concern and refactored out of the DAL. In terms of command timeout, this would be valid, and can be set like so:

    public int CommandTimeout
        {
          get
          {
            return this.DataContext.CommandTimeout;
          }
          set
          {
            this.DataContext.CommandTimeout = value;
          }
        }
    

     

    It's very likely that you can (should) refactor parts of that base class out to other helper classes.

     

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by liurong luo Saturday, November 20, 2010 7:58 AM
    Wednesday, November 17, 2010 11:49 AM
  • All of the business rules and business validation logic will be implemented in our data model
    tier - and not within the UI tier or in any of the UI pages. This will ensure that: 1) a consistent
    set of business rules are used everywhere within the application, 2) we write less code and
    don't repeat ourselves, and 3) we can easily modify/adapt our business rules at a later date and
    not have to update them in dozens of different places across our application.
    Yes.
    DataContext Class.

    Each problem has a solution.
    • Marked as answer by mammadkoma Saturday, November 20, 2010 1:28 PM
    Saturday, November 20, 2010 1:28 PM
  • Yes.

    DataContext class and partial methods.


    Each problem has a solution.
    • Marked as answer by mammadkoma Saturday, November 27, 2010 12:05 PM
    Saturday, November 27, 2010 12:04 PM

All replies

  • Any body don't know?
    Each problem has a solution.
    Tuesday, November 16, 2010 5:51 AM
  • Hi, 

    Now why do you want to keep using that base class? What is in it?

    I would use the Repository pattern where a base Repository<T> generates the context for me, among other features. 

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, November 17, 2010 6:08 AM
  • with this class we can manage all queries and SP executing.
    For example we can find all IP address of people that exacute a certain query in web applications and we can manage all command timeout.

    Each problem has a solution.
    Wednesday, November 17, 2010 6:49 AM
  • Ok, 

    Logging IP addresses does not have anything to do with data access; it should be a separate concern and refactored out of the DAL. In terms of command timeout, this would be valid, and can be set like so:

    public int CommandTimeout
        {
          get
          {
            return this.DataContext.CommandTimeout;
          }
          set
          {
            this.DataContext.CommandTimeout = value;
          }
        }
    

     

    It's very likely that you can (should) refactor parts of that base class out to other helper classes.

     

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by liurong luo Saturday, November 20, 2010 7:58 AM
    Wednesday, November 17, 2010 11:49 AM
  • All of the business rules and business validation logic will be implemented in our data model
    tier - and not within the UI tier or in any of the UI pages. This will ensure that: 1) a consistent
    set of business rules are used everywhere within the application, 2) we write less code and
    don't repeat ourselves, and 3) we can easily modify/adapt our business rules at a later date and
    not have to update them in dozens of different places across our application.
    Yes.
    DataContext Class.

    Each problem has a solution.
    • Marked as answer by mammadkoma Saturday, November 20, 2010 1:28 PM
    Saturday, November 20, 2010 1:28 PM
  • Yes.

    DataContext class and partial methods.


    Each problem has a solution.
    • Marked as answer by mammadkoma Saturday, November 27, 2010 12:05 PM
    Saturday, November 27, 2010 12:04 PM