Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is a good Mapper pattern for information stored in an ini file?
    primarykey
    data
    text
    <p>When designing an n-tier application, I tend to use a pattern adopted and adapted from Lhotka's CSLA framwork. In a nutshell, the Repository layer populates a SqlDataReader and passes the data reader, the instance to be mapped, and the mapping information to the Mapper layer which then populates the instance. </p> <p>This pattern has proved itself over and again in many projects I have worked on for a number of reasons:</p> <ol> <li>It is easy to understand and implement, developers tend to stick to it because they understand what it is doing.</li> <li>It enables very easy reuse of the mappers for inherited classes and well as composite classes.</li> <li>Any changes in the entity, and therefore the mapper assigned to it, cause compile time errors pointing directly to the stored procs that also need to be changed.</li> </ol> <p>Here is some sample repository code:</p> <pre><code>internal static List&lt;CompositeEntities.ContactReportRpa&gt; RetrieveByReportId(int reportId) { CompositeEntities.ContactReportRpa report = null; List&lt;CompositeEntities.ContactReportRpa&gt; reports = new List&lt;CompositeEntities.ContactReportRpa&gt;(); using (SqlConnection conn = DBConnection.GetConnection()) { cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "ContactReportRpa_SEL_ByIdReport"; cmd.Parameters.Add("@IdReport", System.Data.SqlDbType.Int).Value = reportId; conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { report = new CompositeEntities.ContactReportRpa(); ContactReportRpaMapper.Map("IdReportRpa", "IdReport", "IdRecommendation", "IsDisplayed", "Comments", report.Rpa, reader); RpaRecommendationMapper.Map("IdRecommendation", "IdDepartment", "TitleRecommendation", "Description", "DisplayOrderRecommendation", report.Recommendation, reader); RpaDepartmentMapper.Map("IdDepartment", "TitleDepartment", "DisplayOrderDepartment", report.Department, reader); reports.Add(report); } } } return reports; } </code></pre> <p>Here is some sample Mapper Code. It is pretty straightforward: The mapper knows which class property gets mapped to each field in the data reader. The name of each field is passed to the mapper so the same mapper can be used regardless of the names assigned to each field in the sproc.</p> <pre><code>internal static void Map(string fieldId, string fieldName, string fieldDisplayOrder, RpaDepartment entity, SqlDataReader reader) { entity.Id = reader.GetInt32(reader.GetOrdinal(fieldId)); entity.Title = reader.GetString(reader.GetOrdinal(fieldName)); entity.DisplayOrder = reader.GetInt32(reader.GetOrdinal(fieldDisplayOrder)); } </code></pre> <p>So my question is this: How should I implement this pattern when the data source is a text file? I want to stick with this pattern because eventually the data source will be migrated to a db. </p> <p>Any suggestions?</p> <p>EDIT: The ini files already exist and I do not have the go ahead to change them at this time. So I am stuck with them for now.</p>
    singulars
    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.
 

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