循环基类

时间:2016-01-04 02:34:22

标签: .net orm petapoco

我收到以下错误,我已粘贴代码和连接字符串。我是第一次使用PetaPoco。

Circular base class dependency involving 'PetaPoco.DatabaseConfiguration' and 'PetaPoco.DatabaseConfiguration.IBuildConfigurationSettings'  

以下是连接字符串:

 <add name="PriceCheckString" connectionString="Data Source=.;Initial     Catalog=PriceCheck;Integrated Security=SSPI;"
     providerName="System.Data.SqlClient"/>

以下是代码行

      Database priceCheck = new Database("PriceCheckString");
      var ItemPrice = priceCheck.Query<ItemPrice>("SELECT * FROM itemPrice");

2 个答案:

答案 0 :(得分:3)

我有同样的问题,并且能够解决。您必须将接口声明移到DatabaseConfiguration类之外。

在PetaPoco.cs中,使用以下代码替换DatabaseConfiguration类声明:

public interface IBuildConfigurationSettings
{
    /// <summary>
    ///     Sets the setting against the specified key.
    /// </summary>
    /// <param name="key">The setting's key.</param>
    /// <param name="value">The setting's value.</param>
    void SetSetting(string key, object value);

    /// <summary>
    ///     Tries to get the setting and calls the <paramref name="setSetting" /> to set the value if found.
    /// </summary>
    /// <typeparam name="T">The setting type.</typeparam>
    /// <param name="key">The setting's key.</param>
    /// <param name="setSetting">The set setting callback.</param>
    /// <param name="onFail">The on fail callback, called when no setting can be set.</param>
    void TryGetSetting<T>(string key, Action<T> setSetting, Action onFail = null);
}

/// <summary>
///     A helper class which enables fluent configuration.
/// </summary>
public class DatabaseConfiguration : IDatabaseBuildConfiguration, IBuildConfigurationSettings, IHideObjectMethods
{
    private readonly IDictionary<string, object> _settings = new Dictionary<string, object>();

    /// <summary>
    ///     Private constructor to force usage of static build method.
    /// </summary>
    private DatabaseConfiguration()
    {
    }

    /// <summary>
    ///     Starts a new PetaPoco build configuration.
    /// </summary>
    /// <returns>An instance of <see cref="IDatabaseBuildConfiguration" /> to form a fluent interface.</returns>
    public static IDatabaseBuildConfiguration Build()
    {
        return new DatabaseConfiguration();
    }

    public void SetSetting(string key, object value)
    {
        // Note: no argument checking because, pref, enduser unlikely and handled by RT/FW
        if (value != null)
            _settings[key] = value;
        else
            _settings.Remove(key);
    }

    public void TryGetSetting<T>(string key, Action<T> setSetting, Action onFail = null)
    {
        // Note: no argument checking because, pref, enduser unlikely and handled by RT/FW
        object setting;
        if (_settings.TryGetValue(key, out setting))
            setSetting((T) setting);
        else if (onFail != null)
            onFail();
    }
}

您还需要在以下内容中查找/替换(在相同的PetaPoco.cs文件中):

find:((DatabaseConfiguration.IBuildConfigurationSettings)source).SetSetting(key,value);

替换为:((IBuildConfigurationSettings)source).SetSetting(key,value);

答案 1 :(得分:0)

这已在最新版本中修复。版本5.1.114或5.1.109-beta及更高版本

有关详细信息,请参阅PetaPoco issue