Subsonic 在亚音速中创建查询对象时出错

Subsonic 在亚音速中创建查询对象时出错,subsonic,Subsonic,我在我们的一个环境中遇到以下错误。它似乎是在IIS重新启动时发生的,但我们还没有缩小细节来重现它 A DataTable named 'PeoplePassword' already belongs to this DataSet. at System.Data.DataTableCollection.RegisterName(String name, String tbNamespace) at System.Data.DataTableCollection.BaseAdd(DataTabl

我在我们的一个环境中遇到以下错误。它似乎是在IIS重新启动时发生的,但我们还没有缩小细节来重现它

A DataTable named 'PeoplePassword' already belongs to this DataSet. 
at System.Data.DataTableCollection.RegisterName(String name, String tbNamespace)
at System.Data.DataTableCollection.BaseAdd(DataTable table) 
at System.Data.DataTableCollection.Add(DataTable table) 
at SubSonic.SqlDataProvider.GetTableSchema(String tableName, TableType tableType) 
at SubSonic.DataService.GetSchema(String tableName, String providerName, TableType tableType) 
at SubSonic.DataService.GetTableSchema(String tableName, String providerName) 
at SubSonic.Query..ctor(String tableName) 
at Wad.Elbert.Data.Enrollment.FetchByUserId(Int32 userId) 
基于stacktrace,我认为在创建查询对象时,错误发生在方法的第二行。 如果其他人有这个问题,请告诉我。 谢谢

该功能的代码为:

        public static List<Enrollment> FetchByUserId(int userId)
    {
        List<Enrollment> enrollments = new List<Enrollment>();
        SubSonic.Query query = new SubSonic.Query("Enrollment");
        query.SelectList = "userid, prompt, response, validationRegex, validationMessage, responseType, enrollmentSource";
        query.QueryType = SubSonic.QueryType.Select;
        query.AddWhere("userId", userId);
        DataSet dataset = query.ExecuteDataSet();
        if (dataset != null &&
            dataset.Tables.Count > 0)
        {
            foreach (DataRow dr in dataset.Tables[0].Rows)
            {
                enrollments.Add(new Enrollment((int)dr["userId"], dr["prompt"].ToString(), dr["response"].ToString(), dr["validationRegex"] != null ? dr["validationRegex"].ToString() : string.Empty, dr["validationMessage"] != null ? dr["validationMessage"].ToString() : string.Empty, (int)dr["responseType"], (int)dr["enrollmentSource"]));
            }
        }
        return enrollments;
    }
公共静态列表FetchByUserId(int-userId)
{
列表注册=新列表();
SubSonic.Query Query=新的SubSonic.Query(“注册”);
query.SelectList=“userid、prompt、response、validationRegex、validationMessage、responseType、enrollmentSource”;
query.QueryType=SubSonic.QueryType.Select;
query.AddWhere(“userId”,userId);
DataSet数据集=query.ExecuteDataSet();
如果(数据集!=null&&
dataset.Tables.Count>0)
{
foreach(dataset.Tables[0].Rows中的DataRow dr)
{
注册。添加(新注册((int)dr[“userId”]、dr[“prompt”]、ToString()、dr[“response”]、ToString()、dr[“validationRegex”!=null?dr[“validationRegex”]。ToString():string.Empty,dr[“validationMessage”!=null?dr[“validationMessage”]。ToString():string.Empty,(int)dr[“responseType”],(int)dr[“enrollmentSource”]);
}
}
返回注册;
}

这是一个线程问题

亚音速在第一次调用
Subsonic.DataService.GetTableSchema(…)
时加载它的模式,但这不是线程安全的

让我用一个小例子来说明这一点

private static Dictionary<string, DriveInfo> drives = new Dictionary<string, DriveInfo>;

private static DriveInfo GetDrive(string name)
{
    if (drives.Count == 0)
    {
        Thread.Sleep(10000); // fake delay
        foreach(var drive in DriveInfo.GetDrives)
            drives.Add(drive.Name, drive);
    }
    if (drives.ContainsKey(name))
        return drives[name];
    return null;
}

在强制亚音速初始化表格模式本身的方法中。

不是答案,但您使用的是github的最新2.x版本吗?
var count = new SubSonic.Query("Enrollment").GetRecordCount();