新しいコントロールを .NET フォームに追加しました。その値をテーブルに保存したいと思います。テーブルに新しい列を追加しました。MyGeneration Doodads を使用して、このテーブルのデータ アクセス オブジェクトを作成するにはどうすればよいですか? http://www.mygenerationsoftware.com/portal/doodads/cusage/tabid/53/default.aspxを見ました が、「テンプレート」の意味がわかりません。テーブルの doodads を再生成する手順は何ですか?
2374 次
2 に答える
3
これについてはあまり反応がありません... dOOdads は長年サポートされていません。いずれにせよ、dOOdads も使用しており、WPF プロジェクト用に独自のリポジトリを展開しているだけです (ASP ではないことはわかっていますが、単に「プラグ アンド プレイ」できるとは思いません)。これが私の基本ルックアップクラスの例です:
public abstract class BaseLookup<TEntity>
{
// Constructor
protected BaseLookup()
{
this.SubsetIdentifier = null;
}
// Properties
public virtual object SubsetIdentifier { get; set; }
// Public Methods
public abstract IEnumerable<TEntity> Read();
public virtual TEntity ReadSingle()
{
return default(TEntity);
}
// Protected Methods
/// <summary>
/// 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).
/// </summary>
/// <param name="loadSubsetFunc">Specify how to load a set of database records.
/// Return boolean confirmation that records were found.</param>
/// <param name="orderByAction">Specify what should happen to sort the results.</param>
/// <param name="translateRowFunc">Specify how a database record should translate to
/// a model entity. Return the new entity.</param>
/// <param name="moveNextFunc">Specify how the database row pointer should move on.
/// Return FALSE on a call to the final row.</param>
/// <returns>A set of translated entities from the database.</returns>
/// <example><code>
///
/// return base.ReloadRecords(
/// _dOOdad.LoadAll,
/// () =>
/// {
/// _dOOdad.Sort = _dOOdad.GetAutoKeyColumn();
/// },
/// () =>
/// {
/// var entity = new LookupEntity();
/// return entity.PopulateLookupEntity(_dOOdad.CurrentRow.ItemArray);
/// },
/// _dOOdad.MoveNext);
///
/// </code></example>
protected virtual IEnumerable<TEntity> ReloadRecords(Func<bool> loadSubsetFunc,
Action orderByAction, Func<TEntity> translateRowFunc, Func<bool> 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));
}
}
}
ベースルックアップの具体的な実装は次のとおりです。
public class CyclesLookup : BaseLookup<BaseLookupEntity>
{
// Fields & Constructor
private readonly CYCLES _dOOdad;
public CyclesLookup(IDbConnection connection, string library)
{
_dOOdad = OpenConnection(connection, library);
}
// Base Override Methods
public override IEnumerable<BaseLookupEntity> Read()
{
// Clear old result set and settings
_dOOdad.FlushData();
// Reload the records and return them sorted and translated
return base.ReloadRecords(
_dOOdad.LoadAll,
() =>
{
_dOOdad.Sort = _dOOdad.GetAutoKeyColumn();
},
() =>
{
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;
}
}
その PopulateLookupEntity メソッドは単なる拡張メソッドです。
public static T PopulateLookupEntity<T>(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 < rowItems.Length; index++)
{
entity.Attributes[index - attributesFirstIndex] = rowItems[index];
}
return (T)entity;
}
ルックアップ以外の場合、BaseLookup から継承するより複雑な BaseRepository クラスがあります。その場合、PopulateLookupEntity は使用しませんが、次のようなプライベート ヘルパー メソッドを使用します。
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)
};
}
お役に立てれば :-)
于 2013-11-05T08:09:01.613 に答える