Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You wont get much of a response on this... dOOdads have not been supported for many years. Regardless, we use dOOdads too and I just roll my own repositories for my WPF projects (I know it's not ASP, but I don't think you can just "plug-and-play"). Here is an example of my base lookup class:</p> <pre><code>public abstract class BaseLookup&lt;TEntity&gt; { // Constructor protected BaseLookup() { this.SubsetIdentifier = null; } // Properties public virtual object SubsetIdentifier { get; set; } // Public Methods public abstract IEnumerable&lt;TEntity&gt; Read(); public virtual TEntity ReadSingle() { return default(TEntity); } // Protected Methods /// &lt;summary&gt; /// Retrieve translated entities from the database. The methods used to do this /// are specified from the child class as parameters (i.e. Action or Func delegates). /// &lt;/summary&gt; /// &lt;param name="loadSubsetFunc"&gt;Specify how to load a set of database records. /// Return boolean confirmation that records were found.&lt;/param&gt; /// &lt;param name="orderByAction"&gt;Specify what should happen to sort the results.&lt;/param&gt; /// &lt;param name="translateRowFunc"&gt;Specify how a database record should translate to /// a model entity. Return the new entity.&lt;/param&gt; /// &lt;param name="moveNextFunc"&gt;Specify how the database row pointer should move on. /// Return FALSE on a call to the final row.&lt;/param&gt; /// &lt;returns&gt;A set of translated entities from the database.&lt;/returns&gt; /// &lt;example&gt;&lt;code&gt; /// /// return base.ReloadRecords( /// _dOOdad.LoadAll, /// () =&gt; /// { /// _dOOdad.Sort = _dOOdad.GetAutoKeyColumn(); /// }, /// () =&gt; /// { /// var entity = new LookupEntity(); /// return entity.PopulateLookupEntity(_dOOdad.CurrentRow.ItemArray); /// }, /// _dOOdad.MoveNext); /// /// &lt;/code&gt;&lt;/example&gt; protected virtual IEnumerable&lt;TEntity&gt; ReloadRecords(Func&lt;bool&gt; loadSubsetFunc, Action orderByAction, Func&lt;TEntity&gt; translateRowFunc, Func&lt;bool&gt; moveNextFunc) { // If records are found, sort them and return set of entities if (loadSubsetFunc()) { orderByAction(); do { var entity = translateRowFunc(); yield return entity; } while (moveNextFunc()); } else { Debug.WriteLine( string.Format( "# ZERO records found: Returning empty set of {0}.", typeof(TEntity).Name)); } } } </code></pre> <p>And here is a concrete implementation of the base lookup:</p> <pre><code>public class CyclesLookup : BaseLookup&lt;BaseLookupEntity&gt; { // Fields &amp; Constructor private readonly CYCLES _dOOdad; public CyclesLookup(IDbConnection connection, string library) { _dOOdad = OpenConnection(connection, library); } // Base Override Methods public override IEnumerable&lt;BaseLookupEntity&gt; Read() { // Clear old result set and settings _dOOdad.FlushData(); // Reload the records and return them sorted and translated return base.ReloadRecords( _dOOdad.LoadAll, () =&gt; { _dOOdad.Sort = _dOOdad.GetAutoKeyColumn(); }, () =&gt; { var entity = new LookupEntity(); entity.Description = string.Format("Cycles for {0}", _dOOdad.YEAR); return entity.PopulateLookupEntity(_dOOdad.CurrentRow.ItemArray, true); }, _dOOdad.MoveNext); } // Private Helper Methods private static CYCLES OpenConnection(IDbConnection connection, string library) { var dOOdad = new CYCLES(connection); dOOdad.SchemaGlobal = library + "."; return dOOdad; } } </code></pre> <p>That PopulateLookupEntity method is just an extension method:</p> <pre><code>public static T PopulateLookupEntity&lt;T&gt;(this T entity, object[] rowItems, bool noDescription = false) where T : BaseLookupEntity { int id = 0; int.TryParse(rowItems[0].ToString(), out id); entity.RecordID = id; var attributesFirstIndex = 1; if (!noDescription) { entity.Description = rowItems[1].ToString(); attributesFirstIndex = 2; } entity.Attributes = new object[rowItems.Length - attributesFirstIndex]; for (int index = attributesFirstIndex; index &lt; rowItems.Length; index++) { entity.Attributes[index - attributesFirstIndex] = rowItems[index]; } return (T)entity; } </code></pre> <p>For non-lookups, I have a more complex BaseRepository class that inherits from BaseLookup. With that one, I don't use PopulateLookupEntity, but a private helper method like this:</p> <pre><code>private IPlanningGridHeader TranslateCurrentDoodadRow() { return new PlanningGridHeader() { PlanNumber = Convert.ToInt32(_dOOdad.PLANNUMBER), Active = _dOOdad.ACTIVE == 1M, Capturer = _dOOdad.CAPTURER, Region = _dOOdad.REGION, CorporateID = Convert.ToInt32(_dOOdad.CORPORATEID), StartDate = _dOOdad.STARTDATE.ConvertDb2Date(), EndDate = _dOOdad.ENDDATE.ConvertDb2Date(), AdvertStartDate = _dOOdad.ADVERTSTARTDATE.ConvertDb2Date(), AdvertEndDate = _dOOdad.ADVERTENDDATE.ConvertDb2Date(), BpcsDealNumber = Convert.ToInt32(_dOOdad.BPCSDEALNUMBER), Description = _dOOdad.DESCRIPTION, DeactivationReason = _dOOdad.DEACTIVATIONREASON, LastSavedUsername = _dOOdad.LASTUSER, LastSavedDateTime = _dOOdad.LASTDATE.ConvertDb2Date().AddDb2Time(_dOOdad.LASTTIME) }; } </code></pre> <p>Hope this helps :-)</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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