1

我在 .NET 表单中添加了一个新控件,我想将其值保存在表中。我在表中添加了一个新列。如何使用 MyGeneration Doodads 为该表创建数据访问对象?我有看了http://www.mygenerationsoftware.com/portal/doodads/cusage/tabid/53/default.aspx ,但我不明白“模板”是什么意思。为表重新生成doodads的程序是什么?

4

2 回答 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 回答
1

虽然它很旧,但我建议远离这个图书馆。它有一个导致连接泄漏的严重错误,我敢打赌创建者在编码时没有检查 ADO.NET 实践。而且,他不知道如何处理DBNull,所以他在普通属性的旁边发明了“字符串属性”来处理NULL问题,把生成的代码和编程模型弄得一团糟,开发人员正常访问时产生了更多的NullReferenceException值为 null 的属性。

我使用 MyGeneration Doodads 从一个已有 10 多年历史的遗留系统中收集了所有这些问题。很高兴我终于可以摆脱它了。

如果您正在为企业应用程序寻找 DAC 库,请不要选择此库。

于 2020-02-10T20:10:01.243 回答