Sitio web educativo utilizando formas web de ASP.NET -- # campo con performance campo con asp.net campo con database camp codereview Relacionados El problema

Educational website using ASP.NET webforms


6
vote

problema

Español

Nuestro equipo está desarrollando un sitio web educativo utilizando formas web de ASP.NET. Diseñamos DAL & AMP; Clases de BAL y ahora tengo algunas preguntas:

  1. son dal & amp; BAL Diseñado bien?

  2. ¿Sería mejor usar Orm (como EF) en lugar de usar nuestras propias clases? (ORM es lento, pero no estoy seguro)

  3. ¿Debemos ignorar BAL y solo tener dal (2 capas en lugar de 3 capas)?

AVISO QUE:

  • Hay muchos usuarios y éxitos.
  • Cada página necesita una base de datos y hay muchas consultas.
  • El rendimiento y la velocidad son importantes para nuestro equipo.

dal

  // These lines will import the needed namespaces using System; using System.Data;  // Declare our datalayer namespace namespace DataLayer {  #region "Cat_Table Class" // Create the class, based on our table and make it Serializable() // Making it Serializable means that we will be able to store an instance // of our class in a session variable or save and load it from disk [Serializable()] public partial class Cat_Table {  #region "Instance Variables"     protected int m_CatID;     protected string m_CatName;     // The IsDirty flag is set whenever a property is changed     protected bool m_IsDirty;     // The m_ConnectionString holds the connection string     protected string m_ConnectString;     // The m_IsUpdate determines if, when we save a record      // it is an insert or update     protected bool m_IsUpdate;  #endregion  #region "Constructors"     // This is the default empty constructor. Basically     // all it does is setup the connectionstring     public Cat_Table()     {         // Call SetConnectionString() to set our connection string         // for connecting to the database         SetConnectString();         // The m_IsUpdate flag holds weather we are doing an insert or an update         // Since no primary key was passed, this is not an update. Its an insert.         m_IsUpdate = false;     }      // This is the default constructor called when passing a primary key.     // It basically does the same thing as the empty constructor, but it also     // loads the record passed and fills the instances variables     public Cat_Table(int pkPrimaryKey)     {         // The m_IsUpdate flag holds weather we are doing an insert or an update         // Since no primary key was passed, this is not an update. Its an insert.         m_IsUpdate = true;         // Call SetConnectionString() to set our connection string         // for connecting to the database         SetConnectString();         // Call the Get subroutine to load the record and fill the member variables         this.Get(pkPrimaryKey);     }      // This constructor is the default constructor called when     // a datarow is passed. It loads the member variables with the row data     public Cat_Table(DataRow dtrRow)     {         // The m_IsUpdate flag holds weather we are doing an insert or an update         // Since no primary key was passed, this is not an update. Its an insert.         m_IsUpdate = true;         // Call SetConnectionString() to set our connection string         // for connecting to the database         SetConnectString();         // Call the Fill subroutine to fill the member variables with the row passed         this.Fill(dtrRow);     } #endregion  #region "Properties"     // This property sets the CatID Field     public int CatID {         get {           return this.m_CatID; }         set {             // The m_IsDirty flag is set because this row now needs to be saved             this.m_IsDirty = true;             this.m_CatID = value;         }     }      // This property sets the CatName Field     public string CatName {         get {           return this.m_CatName; }         set {             // The m_IsDirty flag is set because this row now needs to be saved             this.m_IsDirty = true;             this.m_CatName = value;         }     }  #endregion  #region "Connection Routines"     // This sub sets our member m_connectString to the value of the connection string,     // As pulled from our Universal file     protected void SetConnectString()     {         m_ConnectString = DataLayer.Universal.GetConnectionString();     }      // This function returns the value of our m_ConnectString variable     protected string GetConnectString()     {         return m_ConnectString;     }      // This function returns our Universal Connect string. It is a shared function     // meaning you can call it without instantiating an instance of this class     protected static string GetConnectionString()     {         return DataLayer.Universal.GetConnectionString();     } #endregion  #region "Copy SubRoutine"     // The Copy subroutine copies the values from     // the DataRow passed into the member variables     public void Copy(DataRow dtrRow)     {         try {             this.m_CatID = (int)dtrRow["CatID"];         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX         }          try {             this.m_CatName = (string)dtrRow["CatName"];         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX         }      } #endregion  #region "Fill SubRoutine"     // Fill Subroutine fills the member variables with a datarow passed to the sub     protected void Fill(DataRow dtrRow)     {         try {             if (((!object.ReferenceEquals(dtrRow["CatID"],  DBNull.Value)))) {                 this.m_CatID = (int)dtrRow["CatID"];                 m_IsUpdate = true;             }         } catch (Exception) {                     m_IsUpdate = false;             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX or you changed the data type for a field         }         try {             if (((!object.ReferenceEquals(dtrRow["CatName"],  DBNull.Value)))) {                 this.m_CatName = (string)dtrRow["CatName"];             }         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX or you changed the data type for a field         }     } #endregion  #region "Get SubRoutine"      // The Get Subroutine retreives a single record based on the     // primary key passed to it. It then fills the member variables     // with the data retrieved     private void Get(int primID)     {         // This variable holds the name of the stored procedure that         // is called to retrieve the record         string storedProcedure = "spCat_TableSelect";         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         // This dataset will hold the results of the stored procedure         DataSet ds;         // This holds our connection string to the database         string ConnectionString = GetConnectString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();         System.Data.SqlClient.SqlDataAdapter da;          conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.StoredProcedure;         cmd.Connection = conn;         cmd.CommandText = storedProcedure;         // This sets up the SQL stored procedure parameter         cmd.Parameters.Add("@CatID", SqlDbType.Int);         cmd.Parameters["@CatID"].Value = primID;          try {             conn.Open();             da = new System.Data.SqlClient.SqlDataAdapter();             da.SelectCommand = cmd;              ds = new DataSet();             da.Fill(ds);              if (ds.Tables.Count > 0) {                 if (ds.Tables[0].Rows.Count > 0) {                     Fill(ds.Tables[0].Rows[0]);                 }             }          } catch (Exception ex) {             // TODO: You may want to add code here to handle any kind             // error that could occur. If the stored procedures were NOT             // modified, then only one of two things usually can throw an error here.             // Possibility number one: The SQL Server is down or cannot be accessed for some reason             // or possibility number two: The stored procedure can not be found             throw ex;         }         conn.Close();     } #endregion  #region "Delete SubRoutine"     // This is the Delete Sub. It deletes the currently loaded record     public void Delete()     {         // This variable holds the name of the stored procedure that         // is called to retrieve the record         string storedProcedure = "spCat_TableDelete";         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         // This holds our connection string to the database         string ConnectionString = GetConnectString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();          conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.StoredProcedure;         cmd.Connection = conn;         cmd.CommandText = storedProcedure;         // This sets up the SQL stored procedure parameter         cmd.Parameters.Add("@CatID", SqlDbType.Int);         cmd.Parameters["@CatID"].Value = this.m_CatID;          try {             conn.Open();             cmd.ExecuteNonQuery();         } catch (Exception ex) {             throw ex;             // TODO: You may want to add code here to handle any kind             // error that could occur. If the stored procedures were NOT             // modified, then only one of three things usually can throw an error here.             // Possibility number one: The SQL Server is down or cannot be accessed for some reason             // or possibility number two: The stored procedure can not be found             // or possibility number three: the record cannot be deleted, possibly because             // of a foreign key conflict         }         conn.Close();     } #endregion  #region "Save Subroutine"      // This sub will either insert or update the current record into the table     public void Save()     {         // This variable holds the name of the stored procedure that         // is called to retrieve the record         string storedProcedure = null;         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         // This holds our connection string to the database         string ConnectionString = GetConnectString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();          // Only update if this record is "dirty"         if (m_IsDirty) {             conn.ConnectionString = ConnectionString;             cmd.Connection = conn;             cmd.CommandType = CommandType.StoredProcedure;              cmd.Parameters.Add("@CatID", SqlDbType.Int);              // Add CatName as a parameter             cmd.Parameters.Add("@CatName", SqlDbType.NVarChar);             if (this.m_CatName != null) {                 cmd.Parameters["@CatName"].Value = this.m_CatName;             } else {                 cmd.Parameters["@CatName"].Value = "";             }              // Test to see if we are updating or inserting             if (m_IsUpdate == true) {                 storedProcedure = "spCat_TableUpdate";                 cmd.CommandText = storedProcedure;                  cmd.Parameters["@CatID"].Value = this.m_CatID;                 cmd.Parameters["@CatID"].Direction = ParameterDirection.Input;                 try {                     conn.Open();                     cmd.ExecuteNonQuery();                 } catch (Exception ex) {                     throw ex;                     // TODO: Write code here to handle any error that could occur.                     // There are many reasons why an error could occur here, such                     // as SQL Server not being found or the stored procedure not                     // being found or perhaps the primary key is a duplicate.                 }                 conn.Close();             } else {                 storedProcedure = "spCat_TableInsert";                 cmd.CommandText = storedProcedure;                  cmd.Parameters["@CatID"].Value = this.m_CatID;                 cmd.Parameters["@CatID"].Direction = ParameterDirection.Output;                 try {                     conn.Open();                     cmd.ExecuteNonQuery();                 } catch (Exception ex) {                     throw ex;                     // TODO: Write code here to handle any error that could occur.                     // There are many reasons why an error could occur here, such                     // as SQL Server not being found or the stored procedure not                     // being found or perhaps the primary key is a duplicate.                 }                 this.m_CatID = (int)cmd.Parameters["@CatID"].Value;                 conn.Close();             }         }     } #endregion  #region "GetAll SubRoutine"     // This function will retrieve ALL the rows in the table     // Use common sense when using this function. Obviously this      // should not be used on large tables. Usually this function is     // used just before populating a drop down list.     public static DataTable GetAll()     {         string storedProcedure = "spCat_TableGetAll";         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         string ConnectionString = GetConnectionString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();          conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.StoredProcedure;         cmd.Connection = conn;         cmd.CommandText = storedProcedure;          try {             DataSet ds;             System.Data.SqlClient.SqlDataAdapter da;             DataTable Table = null;              conn.Open();             da = new System.Data.SqlClient.SqlDataAdapter();             da.SelectCommand = cmd;              ds = new DataSet();             da.Fill(ds);              if (ds.Tables.Count > 0) {                 if (ds.Tables[0].Rows.Count > 0) {                     Table = ds.Tables[0];                 }             }             conn.Close();             return Table;         } catch (Exception ex) {             throw ex;             // TODO: Add code here to catch any kind of error.             // An error would only occur here if 1) The SQL server is down             // or cannot be reached or 2) The GetAll stored procedure cannot             // be found or 3) You are timing out because you are trying to pull too much data         }     } #endregion  #region "GetBySQLStatement SubRoutine"     public static DataTable GetBySQLStatement(string SQLText)     {         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         string ConnectionString = GetConnectionString();         System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection();          Conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.Text;         cmd.Connection = Conn;         cmd.CommandText = SQLText;          try {             DataSet ds;             System.Data.SqlClient.SqlDataAdapter da;             DataTable Table = null;              Conn.Open();             da = new System.Data.SqlClient.SqlDataAdapter();             da.SelectCommand = cmd;              ds = new DataSet();             da.Fill(ds);              if (ds.Tables.Count > 0) {                 if (ds.Tables[0].Rows.Count > 0) {                     Table = ds.Tables[0];                 }             }             Conn.Close();             return Table;         } catch (Exception ex) {             throw ex;         }         Conn.Close();     } #endregion  } #endregion }   

bal

  using System; using System.Data; using System.Collections;  namespace BusinessLayer {  #region "Cat_Table Class" [Serializable()] public class Cat_Table : DataLayer.Cat_Table, BusinessLayer.IBusiness {  #region "Constructors"     public Cat_Table() : base()     {     }      public Cat_Table(int pkPrimaryKey) : base(pkPrimaryKey)     {     }      public Cat_Table(DataRow dtrRow) : base(dtrRow)     {     }  #endregion  #region "Interface Implementation"     public void Rollback()     {     }      public void Validate()     {         // TODO: Write your own validation code     } #endregion  } #endregion  #region "Cat_Tables Class" [Serializable()] public partial class Cat_Tables : CollectionBase, System.Collections.Generic.IEnumerable<BusinessLayer.Cat_Table> {  #region "LINQ implementation"     public new System.Collections.Generic.IEnumerator<BusinessLayer.Cat_Table> GetEnumerator()     {         foreach (BusinessLayer.Cat_Table Cat_TableObj in this.List)         {             yield return Cat_TableObj;         }     } #endregion  #region "Enumerated Sort Fields"     public enum SortFields     {         Sort_CatID,         Sort_CatName     }      public enum SortType     {         Ascending = 1,         Descending = 2     }  #endregion  #region "Sort Comparers"       private class Comp_CatID : IComparer       {         public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;              try {                 return Cat_Table1.CatID.CompareTo(Cat_Table2.CatID);             } catch (Exception) {                 return 0;             }         }     }      private class Comp_CatID_D : IComparer     {          public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;             int j = 0;              try {                 j = Cat_Table1.CatID.CompareTo(Cat_Table2.CatID);                 if (j==1) return -1;                 if (j==-1) return 1;             } catch (Exception) {                 j = 0;             }             return j;         }     }        private class Comp_CatName : IComparer       {         public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;              try {                 return Cat_Table1.CatName.CompareTo(Cat_Table2.CatName);             } catch (Exception) {                 return 0;             }         }     }      private class Comp_CatName_D : IComparer     {          public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;             int j = 0;              try {                 j = Cat_Table1.CatName.CompareTo(Cat_Table2.CatName);                 if (j==1) return -1;                 if (j==-1) return 1;             } catch (Exception) {                 j = 0;             }             return j;         }     }  #endregion  #region "Sort Functions"     public void Sort(SortFields SortField, SortType SortMethod)     {         if (SortField == SortFields.Sort_CatID) {             if (SortMethod == SortType.Ascending) {                 this.InnerList.Sort(new Comp_CatID());             } else {                 this.InnerList.Sort(new Comp_CatID_D());             }         }          if (SortField == SortFields.Sort_CatName) {             if (SortMethod == SortType.Ascending) {                 this.InnerList.Sort(new Comp_CatName());             } else {                 this.InnerList.Sort(new Comp_CatName_D());             }         }      }      public void Sort(SortFields SortField)     {         Sort(SortField, SortType.Ascending);     }  #endregion      #region "Constructors"         public Cat_Tables()         {          }          public Cat_Tables(DataRowCollection datarows) : this()         {             this.Load(datarows);         }     #endregion  #region "Member Functions"     protected void Load(DataRowCollection dataRows)     {         foreach (DataRow dr in dataRows) {             this.Add(new Cat_Table(dr));         }     }      public Cat_Table this[int index] {         get { return (Cat_Table)base.InnerList[index]; }         set { base.InnerList[index] = value; }     }      public int Add(Cat_Table val)     {         return base.InnerList.Add(val);     } #endregion  #region "Save Function"     public void Save()     {         foreach (Cat_Table a in this.InnerList) {             a.Save();         }     } #endregion  #region "Rollback Sub"     public void Rollback()     {         foreach (Cat_Table a in this.InnerList) {             a.Rollback();         }     } #endregion           public void GetBySQLStatement(string SQLText)          {              DataTable dt = DataLayer.Cat_Table.GetBySQLStatement(SQLText);              if (dt != null) {                  this.Load(dt.Rows);              }          }  #region "GetAll Subroutine" // Loads all records from the table into the collection          public void GetAll()          {              DataTable dt = DataLayer.Cat_Table.GetAll();              if (dt != null) {                  this.Load(dt.Rows);              }          }  #endregion      } #endregion }   
Original en ingles

Our team is developing an educational website using ASP.NET webforms. We designed DAL & BAL classes and now I have some questions:

  1. Are DAL & BAL designed well?

  2. Would it be better using ORM (like EF) instead of using our own classes? (ORM is slow, but I'm not sure)

  3. Should we ignore BAL and only have DAL (2 layers instead of 3 layers)?

Notice that:

  • there are many users and hits.
  • every page needs a database and there are many queries.
  • performance and speed are important for our team.

DAL

// These lines will import the needed namespaces using System; using System.Data;  // Declare our datalayer namespace namespace DataLayer {  #region "Cat_Table Class" // Create the class, based on our table and make it Serializable() // Making it Serializable means that we will be able to store an instance // of our class in a session variable or save and load it from disk [Serializable()] public partial class Cat_Table {  #region "Instance Variables"     protected int m_CatID;     protected string m_CatName;     // The IsDirty flag is set whenever a property is changed     protected bool m_IsDirty;     // The m_ConnectionString holds the connection string     protected string m_ConnectString;     // The m_IsUpdate determines if, when we save a record      // it is an insert or update     protected bool m_IsUpdate;  #endregion  #region "Constructors"     // This is the default empty constructor. Basically     // all it does is setup the connectionstring     public Cat_Table()     {         // Call SetConnectionString() to set our connection string         // for connecting to the database         SetConnectString();         // The m_IsUpdate flag holds weather we are doing an insert or an update         // Since no primary key was passed, this is not an update. Its an insert.         m_IsUpdate = false;     }      // This is the default constructor called when passing a primary key.     // It basically does the same thing as the empty constructor, but it also     // loads the record passed and fills the instances variables     public Cat_Table(int pkPrimaryKey)     {         // The m_IsUpdate flag holds weather we are doing an insert or an update         // Since no primary key was passed, this is not an update. Its an insert.         m_IsUpdate = true;         // Call SetConnectionString() to set our connection string         // for connecting to the database         SetConnectString();         // Call the Get subroutine to load the record and fill the member variables         this.Get(pkPrimaryKey);     }      // This constructor is the default constructor called when     // a datarow is passed. It loads the member variables with the row data     public Cat_Table(DataRow dtrRow)     {         // The m_IsUpdate flag holds weather we are doing an insert or an update         // Since no primary key was passed, this is not an update. Its an insert.         m_IsUpdate = true;         // Call SetConnectionString() to set our connection string         // for connecting to the database         SetConnectString();         // Call the Fill subroutine to fill the member variables with the row passed         this.Fill(dtrRow);     } #endregion  #region "Properties"     // This property sets the CatID Field     public int CatID {         get {           return this.m_CatID; }         set {             // The m_IsDirty flag is set because this row now needs to be saved             this.m_IsDirty = true;             this.m_CatID = value;         }     }      // This property sets the CatName Field     public string CatName {         get {           return this.m_CatName; }         set {             // The m_IsDirty flag is set because this row now needs to be saved             this.m_IsDirty = true;             this.m_CatName = value;         }     }  #endregion  #region "Connection Routines"     // This sub sets our member m_connectString to the value of the connection string,     // As pulled from our Universal file     protected void SetConnectString()     {         m_ConnectString = DataLayer.Universal.GetConnectionString();     }      // This function returns the value of our m_ConnectString variable     protected string GetConnectString()     {         return m_ConnectString;     }      // This function returns our Universal Connect string. It is a shared function     // meaning you can call it without instantiating an instance of this class     protected static string GetConnectionString()     {         return DataLayer.Universal.GetConnectionString();     } #endregion  #region "Copy SubRoutine"     // The Copy subroutine copies the values from     // the DataRow passed into the member variables     public void Copy(DataRow dtrRow)     {         try {             this.m_CatID = (int)dtrRow["CatID"];         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX         }          try {             this.m_CatName = (string)dtrRow["CatName"];         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX         }      } #endregion  #region "Fill SubRoutine"     // Fill Subroutine fills the member variables with a datarow passed to the sub     protected void Fill(DataRow dtrRow)     {         try {             if (((!object.ReferenceEquals(dtrRow["CatID"],  DBNull.Value)))) {                 this.m_CatID = (int)dtrRow["CatID"];                 m_IsUpdate = true;             }         } catch (Exception) {                     m_IsUpdate = false;             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX or you changed the data type for a field         }         try {             if (((!object.ReferenceEquals(dtrRow["CatName"],  DBNull.Value)))) {                 this.m_CatName = (string)dtrRow["CatName"];             }         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX or you changed the data type for a field         }     } #endregion  #region "Get SubRoutine"      // The Get Subroutine retreives a single record based on the     // primary key passed to it. It then fills the member variables     // with the data retrieved     private void Get(int primID)     {         // This variable holds the name of the stored procedure that         // is called to retrieve the record         string storedProcedure = "spCat_TableSelect";         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         // This dataset will hold the results of the stored procedure         DataSet ds;         // This holds our connection string to the database         string ConnectionString = GetConnectString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();         System.Data.SqlClient.SqlDataAdapter da;          conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.StoredProcedure;         cmd.Connection = conn;         cmd.CommandText = storedProcedure;         // This sets up the SQL stored procedure parameter         cmd.Parameters.Add("@CatID", SqlDbType.Int);         cmd.Parameters["@CatID"].Value = primID;          try {             conn.Open();             da = new System.Data.SqlClient.SqlDataAdapter();             da.SelectCommand = cmd;              ds = new DataSet();             da.Fill(ds);              if (ds.Tables.Count > 0) {                 if (ds.Tables[0].Rows.Count > 0) {                     Fill(ds.Tables[0].Rows[0]);                 }             }          } catch (Exception ex) {             // TODO: You may want to add code here to handle any kind             // error that could occur. If the stored procedures were NOT             // modified, then only one of two things usually can throw an error here.             // Possibility number one: The SQL Server is down or cannot be accessed for some reason             // or possibility number two: The stored procedure can not be found             throw ex;         }         conn.Close();     } #endregion  #region "Delete SubRoutine"     // This is the Delete Sub. It deletes the currently loaded record     public void Delete()     {         // This variable holds the name of the stored procedure that         // is called to retrieve the record         string storedProcedure = "spCat_TableDelete";         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         // This holds our connection string to the database         string ConnectionString = GetConnectString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();          conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.StoredProcedure;         cmd.Connection = conn;         cmd.CommandText = storedProcedure;         // This sets up the SQL stored procedure parameter         cmd.Parameters.Add("@CatID", SqlDbType.Int);         cmd.Parameters["@CatID"].Value = this.m_CatID;          try {             conn.Open();             cmd.ExecuteNonQuery();         } catch (Exception ex) {             throw ex;             // TODO: You may want to add code here to handle any kind             // error that could occur. If the stored procedures were NOT             // modified, then only one of three things usually can throw an error here.             // Possibility number one: The SQL Server is down or cannot be accessed for some reason             // or possibility number two: The stored procedure can not be found             // or possibility number three: the record cannot be deleted, possibly because             // of a foreign key conflict         }         conn.Close();     } #endregion  #region "Save Subroutine"      // This sub will either insert or update the current record into the table     public void Save()     {         // This variable holds the name of the stored procedure that         // is called to retrieve the record         string storedProcedure = null;         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         // This holds our connection string to the database         string ConnectionString = GetConnectString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();          // Only update if this record is "dirty"         if (m_IsDirty) {             conn.ConnectionString = ConnectionString;             cmd.Connection = conn;             cmd.CommandType = CommandType.StoredProcedure;              cmd.Parameters.Add("@CatID", SqlDbType.Int);              // Add CatName as a parameter             cmd.Parameters.Add("@CatName", SqlDbType.NVarChar);             if (this.m_CatName != null) {                 cmd.Parameters["@CatName"].Value = this.m_CatName;             } else {                 cmd.Parameters["@CatName"].Value = "";             }              // Test to see if we are updating or inserting             if (m_IsUpdate == true) {                 storedProcedure = "spCat_TableUpdate";                 cmd.CommandText = storedProcedure;                  cmd.Parameters["@CatID"].Value = this.m_CatID;                 cmd.Parameters["@CatID"].Direction = ParameterDirection.Input;                 try {                     conn.Open();                     cmd.ExecuteNonQuery();                 } catch (Exception ex) {                     throw ex;                     // TODO: Write code here to handle any error that could occur.                     // There are many reasons why an error could occur here, such                     // as SQL Server not being found or the stored procedure not                     // being found or perhaps the primary key is a duplicate.                 }                 conn.Close();             } else {                 storedProcedure = "spCat_TableInsert";                 cmd.CommandText = storedProcedure;                  cmd.Parameters["@CatID"].Value = this.m_CatID;                 cmd.Parameters["@CatID"].Direction = ParameterDirection.Output;                 try {                     conn.Open();                     cmd.ExecuteNonQuery();                 } catch (Exception ex) {                     throw ex;                     // TODO: Write code here to handle any error that could occur.                     // There are many reasons why an error could occur here, such                     // as SQL Server not being found or the stored procedure not                     // being found or perhaps the primary key is a duplicate.                 }                 this.m_CatID = (int)cmd.Parameters["@CatID"].Value;                 conn.Close();             }         }     } #endregion  #region "GetAll SubRoutine"     // This function will retrieve ALL the rows in the table     // Use common sense when using this function. Obviously this      // should not be used on large tables. Usually this function is     // used just before populating a drop down list.     public static DataTable GetAll()     {         string storedProcedure = "spCat_TableGetAll";         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         string ConnectionString = GetConnectionString();         System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();          conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.StoredProcedure;         cmd.Connection = conn;         cmd.CommandText = storedProcedure;          try {             DataSet ds;             System.Data.SqlClient.SqlDataAdapter da;             DataTable Table = null;              conn.Open();             da = new System.Data.SqlClient.SqlDataAdapter();             da.SelectCommand = cmd;              ds = new DataSet();             da.Fill(ds);              if (ds.Tables.Count > 0) {                 if (ds.Tables[0].Rows.Count > 0) {                     Table = ds.Tables[0];                 }             }             conn.Close();             return Table;         } catch (Exception ex) {             throw ex;             // TODO: Add code here to catch any kind of error.             // An error would only occur here if 1) The SQL server is down             // or cannot be reached or 2) The GetAll stored procedure cannot             // be found or 3) You are timing out because you are trying to pull too much data         }     } #endregion  #region "GetBySQLStatement SubRoutine"     public static DataTable GetBySQLStatement(string SQLText)     {         System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();         string ConnectionString = GetConnectionString();         System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection();          Conn.ConnectionString = ConnectionString;         cmd.CommandType = CommandType.Text;         cmd.Connection = Conn;         cmd.CommandText = SQLText;          try {             DataSet ds;             System.Data.SqlClient.SqlDataAdapter da;             DataTable Table = null;              Conn.Open();             da = new System.Data.SqlClient.SqlDataAdapter();             da.SelectCommand = cmd;              ds = new DataSet();             da.Fill(ds);              if (ds.Tables.Count > 0) {                 if (ds.Tables[0].Rows.Count > 0) {                     Table = ds.Tables[0];                 }             }             Conn.Close();             return Table;         } catch (Exception ex) {             throw ex;         }         Conn.Close();     } #endregion  } #endregion } 

BAL

using System; using System.Data; using System.Collections;  namespace BusinessLayer {  #region "Cat_Table Class" [Serializable()] public class Cat_Table : DataLayer.Cat_Table, BusinessLayer.IBusiness {  #region "Constructors"     public Cat_Table() : base()     {     }      public Cat_Table(int pkPrimaryKey) : base(pkPrimaryKey)     {     }      public Cat_Table(DataRow dtrRow) : base(dtrRow)     {     }  #endregion  #region "Interface Implementation"     public void Rollback()     {     }      public void Validate()     {         // TODO: Write your own validation code     } #endregion  } #endregion  #region "Cat_Tables Class" [Serializable()] public partial class Cat_Tables : CollectionBase, System.Collections.Generic.IEnumerable<BusinessLayer.Cat_Table> {  #region "LINQ implementation"     public new System.Collections.Generic.IEnumerator<BusinessLayer.Cat_Table> GetEnumerator()     {         foreach (BusinessLayer.Cat_Table Cat_TableObj in this.List)         {             yield return Cat_TableObj;         }     } #endregion  #region "Enumerated Sort Fields"     public enum SortFields     {         Sort_CatID,         Sort_CatName     }      public enum SortType     {         Ascending = 1,         Descending = 2     }  #endregion  #region "Sort Comparers"       private class Comp_CatID : IComparer       {         public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;              try {                 return Cat_Table1.CatID.CompareTo(Cat_Table2.CatID);             } catch (Exception) {                 return 0;             }         }     }      private class Comp_CatID_D : IComparer     {          public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;             int j = 0;              try {                 j = Cat_Table1.CatID.CompareTo(Cat_Table2.CatID);                 if (j==1) return -1;                 if (j==-1) return 1;             } catch (Exception) {                 j = 0;             }             return j;         }     }        private class Comp_CatName : IComparer       {         public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;              try {                 return Cat_Table1.CatName.CompareTo(Cat_Table2.CatName);             } catch (Exception) {                 return 0;             }         }     }      private class Comp_CatName_D : IComparer     {          public int Compare(object x, object y)         {             BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;             BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;             int j = 0;              try {                 j = Cat_Table1.CatName.CompareTo(Cat_Table2.CatName);                 if (j==1) return -1;                 if (j==-1) return 1;             } catch (Exception) {                 j = 0;             }             return j;         }     }  #endregion  #region "Sort Functions"     public void Sort(SortFields SortField, SortType SortMethod)     {         if (SortField == SortFields.Sort_CatID) {             if (SortMethod == SortType.Ascending) {                 this.InnerList.Sort(new Comp_CatID());             } else {                 this.InnerList.Sort(new Comp_CatID_D());             }         }          if (SortField == SortFields.Sort_CatName) {             if (SortMethod == SortType.Ascending) {                 this.InnerList.Sort(new Comp_CatName());             } else {                 this.InnerList.Sort(new Comp_CatName_D());             }         }      }      public void Sort(SortFields SortField)     {         Sort(SortField, SortType.Ascending);     }  #endregion      #region "Constructors"         public Cat_Tables()         {          }          public Cat_Tables(DataRowCollection datarows) : this()         {             this.Load(datarows);         }     #endregion  #region "Member Functions"     protected void Load(DataRowCollection dataRows)     {         foreach (DataRow dr in dataRows) {             this.Add(new Cat_Table(dr));         }     }      public Cat_Table this[int index] {         get { return (Cat_Table)base.InnerList[index]; }         set { base.InnerList[index] = value; }     }      public int Add(Cat_Table val)     {         return base.InnerList.Add(val);     } #endregion  #region "Save Function"     public void Save()     {         foreach (Cat_Table a in this.InnerList) {             a.Save();         }     } #endregion  #region "Rollback Sub"     public void Rollback()     {         foreach (Cat_Table a in this.InnerList) {             a.Rollback();         }     } #endregion           public void GetBySQLStatement(string SQLText)          {              DataTable dt = DataLayer.Cat_Table.GetBySQLStatement(SQLText);              if (dt != null) {                  this.Load(dt.Rows);              }          }  #region "GetAll Subroutine" // Loads all records from the table into the collection          public void GetAll()          {              DataTable dt = DataLayer.Cat_Table.GetAll();              if (dt != null) {                  this.Load(dt.Rows);              }          }  #endregion      } #endregion } 
           

Lista de respuestas

7
 
vote
vote
La mejor respuesta
 
  Cast<double>.SequenceEqual2  

Ves lo feo que es esto. Use el Cast<double>.SequenceEqual3 para que pueda tener comparaciones fuertemente escritas que no requieren fundiciones.

MSDN


  Cast<double>.SequenceEqual4  

Si algo salió mal tantosamente, tira una excepción, ¡simplemente fingiremos que son iguales? Esto es lógicamente incorrecto y lo causará muy duro para rastrear los errores.


  Cast<double>.SequenceEqual5  

también conocido como

  Cast<double>.SequenceEqual6  

  Cast<double>.SequenceEqual7  

Clases Use la fase de cámaras superiores a la convención de nombramiento.


  Cast<double>.SequenceEqual8  

Usa nombres más descriptivos. Esto convertirá la línea de código anterior en esto:

  Cast<double>.SequenceEqual9  

  if (M != other.M || N != other.N) {     return false; }  for (int i = 0; i < M; i++) {     for (int j = 0; j < N; j++)     {         if (_values[i, j] != other._values[i, j])         {             return false;         }     } }  return true; 0  

Los enumeres también son de cámare superior.


  if (M != other.M || N != other.N) {     return false; }  for (int i = 0; i < M; i++) {     for (int j = 0; j < N; j++)     {         if (_values[i, j] != other._values[i, j])         {             return false;         }     } }  return true; 1  

¡No hay notación húngara!


Por último, pero no menos importante:

use un orm

Obteniendo un ORM adecuado para arriba y en ejecución es Muy Difícil de obtener a la derecha y creando su propio Usted está

  • introduciendo código de buggy
  • usando un subconjunto muy limitado de un ORM Full Blown
  • Perder el rendimiento (sí, perdiendo): te estás perdiendo en caché y otras técnicas de optimización
  • Codificación dura las dependencias de la base de datos
 
private class Comp_CatName_D : IComparer {      public int Compare(object x, object y)     {         BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x;         BusinessLayer.Cat_Table Cat_Table2 = (BusinessLayer.Cat_Table)y;     } } 

You see how ugly this is. Use the generic IComparer<T> so you can have strongly typed comparisons which don't require casts.

MSDN


try {     return Cat_Table1.CatName.CompareTo(Cat_Table2.CatName); } catch (Exception) {     return 0; } 

If something went wrong so badly it throws an exception, we'll just pretend they're the same? This is logically incorrect and will cause very hard to track down bugs.


try {     j = Cat_Table1.CatName.CompareTo(Cat_Table2.CatName);     if (j==1) return -1;     if (j==-1) return 1; } catch (Exception) {     j = 0; } return j; 

Also known as

return -Cat_Table1.CatName.CompareTo(Cat_Table2.CatName); 

class Cat_Tables 

Classes use UpperCamelCase as naming convention.


foreach (BusinessLayer.Cat_Table Cat_TableObj in this.List) 

use more descriptive names. This will turn the previous line of code in this:

foreach(var table in tables) 

public enum SortFields {     Sort_CatID,     Sort_CatName } 

Enums are UpperCamelCase as well.


protected int m_CatID; 

No hungarian notation!


Last but not least:

USE AN ORM

Getting a proper ORM up and running is very hard to get right and by creating your own you are

  • Introducing buggy code
  • Using a very limited subset of a full blown ORM
  • Losing performance (yes, losing): you're missing out on caching and other optimization techniques
  • Hardcoding the database dependencies
 
 
5
 
vote

comentarios

Tiene muchos comentarios inútiles en su código que deben eliminarse porque no agregue ningún valor al código, sino que reduzca la legibilidad.

Una muy buena respuesta sobre el uso de los comentarios se puede encontrar aquí: https://codereview.stackexchange.com/a / 90113/29371

"Sin embargo,

Línea inferior es que los comentarios en su código deben completar los espacios en blanco que su código no. Además, sus comentarios deben dar detalles sobre la motivación, y no la aplicación de su código. Debería, en general, comentar solo sobre por qué su código hace las cosas, no lo que está haciendo su código.


regiones

El uso de regiones es principalmente un olor a código y debe evitarse.

Una muy buena respuesta sobre el uso de las regiones se puede encontrar aquí: https://softwareengineering.stackexchange.com/a/53114

El código revisado también contenía muchas regiones que agrupan todos los campos juntos, todas las propiedades juntas, etc. Esto tuvo un problema obvio: crecimiento del código fuente.

Cuando abre un archivo y vea una enorme lista de campos, está más inclinado a refactorizar la clase primero, luego trabaje con código. Con las regiones, usted toma un hábito de colapsar cosas y olvidarlo.

Otro problema es que si lo haces en todas partes, te encontrarás creando regiones de un bloque, lo que no tiene ningún sentido. Este fue en realidad el caso en el código que revisé, donde había un montón de constructor de #Región que contiene un constructor.


constructor

Actualmente usted tiene un código duplicado en sus constructores que se pueden reducir utilizando el encadenamiento constructor. El encadenamiento constructor es un enfoque donde un constructor llama a otro constructor en la misma clase o en la base.

Esto llevaría a

  private Cat_Table(bool isUpdate) {     SetConnectString();     m_IsUpdate = isUpdate; }  public Cat_Table()     : this(false) { }  // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)     : this(true) {     this.Get(pkPrimaryKey); }  // This constructor is the default constructor called when // a datarow is passed. It loads the member variables with the row data public Cat_Table(DataRow dtrRow)     : this(true) {     this.Fill(dtrRow); }     

En lugar de usar los comentarios "predeterminados", debe considerar usar la documentación XML correcta para comentar el propósito de los métodos. De esta manera también verás los comentarios en Intellisense.

así que este

  // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)     

debería parecer

  /// <summary> /// This is the default constructor called when passing a primary key.... /// </summary> /// <param name="pkPrimaryKey">The primary key to fill the instance variables</param> public Cat_Table(int pkPrimaryKey)     

El uso del indicador m_IsDirty se puede optimizar. En este momento, no se comprueba si el nuevo valor es diferente del valor actual. Si el valor que se establece es el mismo, entonces no debería necesitar configurar este indicador y, tampoco, no tendrá que guardar la fila actual tampoco.


  protected void SetConnectString()     

Esto no hace lo que implica el nombre del método. No lo hace Set la cadena de conexión pero leíela de un archivo. Debe considerar cambiarlo de nombre a E.G FillConnectionString() o ReadConnectionString() .


 

Comments

You have a lot of useless comments in your code which should be deleted because thy don't add any value to the code but reduce the readability.

A very good answer about the usage of comments can be found here: https://codereview.stackexchange.com/a/90113/29371

Bottom line, though, is that the comments in your code should fill in the blanks that your code does not. In addition, your comments should give details on the motivation, and not the application of your code. You should, in general, comment only on why your code does things, not what your code is doing.


Regions

Using regions is mostly a code smell and should be avoided.

A very good answer about the usage of regions can be found here: https://softwareengineering.stackexchange.com/a/53114

The reviewed code also contained a lot of regions grouping all the fields together, all the properties together, etc. This had an obvious problem: source code growth.

When you open a file and see a huge list of fields, you are more inclined to refactor the class first, then work with code. With regions, you take an habit of collapsing stuff and forgetting about it.

Another problem is that if you do it everywhere, you'll find yourself creating one-block regions, which doesn't make any sense. This was actually the case in the code I reviewed, where there were lots of #region Constructor containing one constructor.


Constructor

Currently you have duplicated code in your constructors which can be reduced by using constructor chaining. Constructor chaining is an approach where a constructor calls another constructor in the same or base class.

This would lead to

private Cat_Table(bool isUpdate) {     SetConnectString();     m_IsUpdate = isUpdate; }  public Cat_Table()     : this(false) { }  // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)     : this(true) {     this.Get(pkPrimaryKey); }  // This constructor is the default constructor called when // a datarow is passed. It loads the member variables with the row data public Cat_Table(DataRow dtrRow)     : this(true) {     this.Fill(dtrRow); }   

Instead of using "default" comments you should consider to use correct xml documentation for commenting the purpose of the methods. In this way you will see the comments in intellisense too.

So this

// This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)   

should look like

/// <summary> /// This is the default constructor called when passing a primary key.... /// </summary> /// <param name="pkPrimaryKey">The primary key to fill the instance variables</param> public Cat_Table(int pkPrimaryKey)   

The usage of the m_IsDirty flag can be optimized. Right now you don't check wether the new value is different from the current value. If the value which is set is the same, then you shouldn't need to set this flag and therefor you won't need to save the current row either.


protected void SetConnectString()   

this does not do what the method name implies. It does not Set the connection string but read it from a file. You should consider to rename it to e.g FillConnectionString() or ReadConnectionString().


 
 
5
 
vote

Jeroen ya ha cubierto algunos de los problemas con Comp_CatID m_IsDirty9 / 99887776655443310 998877665554433111 , pero hay otro:

  // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)   2  

99887776655443313 < / a> lo hace no garantiza que solo regresará -1, 0 o 1., por lo que, si 99887766555443314 , este método devolverá 2.

Tampoco quieres hacer esto:

  // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)   5  

(intente ejecutar // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey) 6 )

Sugeriría que retire las clases y, en su lugar, use // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey) 7 Así:

  // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey)   8  

etc.

Consulte la lista de > // This is the default constructor called when passing a primary key. // It basically does the same thing as the empty constructor, but it also // loads the record passed and fills the instances variables public Cat_Table(int pkPrimaryKey) 9 sobrecargas Para ver cuál es el adecuado para su caso de uso.

 

Jeroen has already covered some of the problems with Comp_CatID/Comp_CatID_D/Comp_CatName/Comp_CatName_D, but there's another one:

try {     j = Cat_Table1.CatID.CompareTo(Cat_Table2.CatID);     if (j==1) return -1;     if (j==-1) return 1; } catch (Exception) {     j = 0; } return j; 

IComparable<T>.CompareTo(T) does not guarantee that it will only ever return -1, 0, or 1. So if j == 2, this method will return 2.

You also don't want to do this:

return -Cat_Table1.CatName.CompareTo(Cat_Table2.CatName); 

(try running int x = int.MinValue; Console.WriteLine(x == -x);)

I would suggest that you remove the classes and instead use List<T>.Sort(Comparison<T>) like so:

// sort by CatID ascending this.InnerList.Sort((x, y) => x.CatID.CompareTo(y.CatID));  // sort by CatID descending this.InnerList.Sort((x, y) => y.CatID.CompareTo(x.CatID));  // sort by CatName ascending this.InnerList.Sort((x, y) => string.Compare(x.CatName, y.CatName)); 

etc.

Please see the list of string.Compare overloads to see which one is right for your use-case.

 
 
3
 
vote

Solo dos notas muy rápidas.

  1. No voy a discutir sobre los estilos de apoyo de una manera u otra, pero sean consistentes !
      public void Copy(DataRow dtrRow)     {         try {             this.m_CatID = (int)dtrRow["CatID"];         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX         }   

La mayoría de los editores tienen un atajo de teclado para esto. Apréngalo y úsalo.

  1. que todo comentario ... en lugar de decirlo podría quiere atrapar bla bla bla, simplemente no atrapes en absoluto. Será mejor que tengas una razón muy buena para tragar todas las excepciones posibles que podrían ocurrir. No parece que lo hagas. Si lo haces, necesitas un mejor comentario.

  2. No dejes métodos vacíos sin explicarte a ti mismo.

      #region "Interface Implementation" public void Rollback() { }   public void Validate() {     // TODO: Write your own validation code }   

    Realmente necesitas explicarte a tu yo futuro por qué esto no se ha implementado.

 

Just two very quick notes.

  1. I'm not going to argue about brace styles one way or the other, but be consistent!
    public void Copy(DataRow dtrRow)     {         try {             this.m_CatID = (int)dtrRow["CatID"];         } catch (Exception) {             // TODO: You might want to add code here to trap any             // errors that might occur             // Usually the only way an error would occur at this particular             // spot is if a field was removed from the database and this file was not             // updated by LayerGen MMX         } 

Most editors have a keyboard shortcut for this. Learn it and use it.

  1. That TODO comment... Instead of saying you might want to catch Blah blah blah, just don't catch at all. You better have a really good reason to swallow every possible exception that could ever occur. It doesn't look like you do. If you do, you need a better comment.

  2. Don't leave empty methods without explaining yourself.

    #region "Interface Implementation" public void Rollback() { }   public void Validate() {     // TODO: Write your own validation code } 

    You really need to explain to your future self why this hasn't been implemented.

 
 

Relacionados problema

2  Método de filtro DataGrid Muy lento  ( Datagrid filter method very slow ) 
Estoy teniendo muchos problemas en mi programa de base de datos con el intento de implementar un método de filtrado efectivo de DataGrid. Después de tomar con...

2  Objeto de búsqueda de la base de datos, o fetchlo usando una API si no está ahí  ( Fetch object from database or fetch it using an api if it isnt there ) 
Para dar algunos antecedentes en este código en particular, hay un controlador que recibe un objeto, las partes de los hashes y se analiza en una base de dato...

3  Mi primer modelo de prueba en phpunit  ( My first model test in phpunit ) 
Acabo de crear una prueba para crear mi clase de pasarela. He escrito alrededor de 8 pruebas y todos estamos pasando. Espero que cualquiera pueda ofrecer cual...

5  Sincronización de una conexión ODBC  ( Synchronization of an odbc connection ) 
Dado que estoy aventurándose cada vez más en el multithreading, ahora tengo que pensar en cómo proteger mi precioso 9988776665544331 de romper en tiempos al...

10  Insertar un valor de DBNULL en una base de datos  ( Inserting a dbnull value into a database ) 
Tengo código que funciona bastante bien. Solo necesito algunas de sus opiniones sobre cómo escribirlo mejor con menos línea de código. Quiero usar un operador...

2  Custom C # Dapper Orm Wrapper  ( Custom c dapper orm wrapper ) 
I am IC # .NET Developer por unos años ... Últimos dos meses he empezado a estudiar los patrones de diseño y los principios de la arquitectura de software emp...

2  Sesión nhibernate y implementación de transacciones  ( Nhibernate session and transaction implementation ) 
Para crear una arquitectura de acoplamiento suelto en mis aplicaciones web, he creado mi propia implementación para ORM, en este caso, NHibernate. Quiero qu...

3  Personalizar los tipos de datos en un modelo generado con hibernación  ( Customize data types in a generated model with hibernate ) 
Tengo una aplicación de primavera / hibernación con la siguiente clase de dominio (código irrelevante despojado de brevedad): @Entity @Data public class Pr...

4  Formularios: campos ordenados contra iteraciones dinámicas  ( Forms ordered fields vs dynamic iterations ) 
He hecho aproximadamente 2 formularios que tienen una acción del lado del servidor usando PHP. Para el primero, hice una variable para cada campo de forma y l...

4  Dos clases de Python para actualizar una base de datos RRD  ( Two python classes to update an rrd database ) 
La primera clase de Python a continuación se usa en uno de mis proyectos actuales y es un enfoque totalmente diferente para cómo normalmente tomaría las cosas...




© 2022 respuesta.top Reservados todos los derechos. Centro de preguntas y respuestas reservados todos los derechos