Note that there are some explanatory texts on larger screens.

plurals
  1. POReflection performance for Data Access Layer
    primarykey
    data
    text
    <p>I had created a framework for a project in the past that one of it’s functionalities was to load the Database info into my business entity classes (only properties no methods) and from the Business entity classes to the database loading the parameters collection of the stored procedure to be executed. To this on that project I decorated the Business Entity Classes with the DB Filed info and SP Parameters like the sample below and let the framework load the entity or the Parameters collection using reflection so I didn’t had to generate new code for the maintenances.<br/> But now I am creating a new and much bigger project, of course much more code to maintain, but where performance is critical and was wondering if it’s worth using reflection for all the load and kept the code much simpler or actually generate all the code and maintain all the changes?<br/> I had did some search, read some of the documentation on MSDN, but still found lots of different opinions, people that liked reflection showing numbers that the overhead is not that bad, and others saying that it’s actually better to keep away from reflection <br/><br/> Technical specs for the new app:<br/> Language: C#<br/> .Net Version: 3.5<br/> Application Type: Classic Web Forms accessing Logic components and Data Access Tier also in C#<br/> Database: SQL Server 2008<br/> Database Abstraction Layer: All access to the DB is made via Stored Procedures and User Defined Functions.<br/> <br/><br/> Sample Code:<br/></p> <pre><code> // Decorated class [System.Serializable()] public class bMyBusinessEntity{ private Int64 _MyEntityID; private string _MyEntityName; private string _MyEntityDescription; [aFieldDataSource(DataColumn = "MyEntityID")] [aRequiredField(ErrorMessage = "The field My Entity ID is mandatory!")] [aFieldSPParameter(ParameterName="MyEntityID")] public Int64 MyEntityID{ get { return _MyEntityID; } set { _MyEntityID = value; } } [aFieldDataSource(DataColumn = "MyEntityName")] [aFieldSPParameter(ParameterName = "MyEntityName")] public string MyEntityName{ get { return _MyEntityName; } set { _MyEntityName = value; } } [aFieldDataSource(DataColumn = "MyEntityDescription")] [aFieldSPParameter(ParameterName = "MyEntityDescription")] public string MyEntityDescription{ get { return _MyEntityDescription; } set { _MyEntityDescription = value; } } } // To Load from DB to the Object: using (DataTable dtblMyEntities = objDataSource.ExecuteProcedure(strSPName, objParams)) { if (dtblMyEntities.Rows.Count &gt; 0) { DataRow drw = dtblMyEntities.Rows[0]; oFieldDataSource.LoadInfo(ref objMyEntity, drw); return objMyEntity; } else throw new Exception(“Row not found!”); } // To Load from the Object to the DB oDataSource objDataSource = new oDataSource(); IDbDataParameter[] objParams = objDataSource.GetProcedureParameters(strSPName); oFieldSPParameter.LoadInfo(objParams, objMyEntity); objDataSource.ExecuteNonQuery(strSPName, objParams); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload