我对存储库和模拟存储库相当新,所以我想帮助理解这个错误究竟意味着什么,以及如何避免它。我查看了其他帖子并完成了我的研究,但它们对于他们的错误太具体了。 破解的代码是
public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
return PersistComponentDb(componentDb);
}
我知道该函数正在调用自身,但是如何阻止它执行此操作?它持久存储模拟存储库,硬编码值看起来像这样
public DataTable GetComponentDbs(int? forComponentId = null, int? forDbServerId = null, int? forEntityId = null)
{
DataTable componentDbs = new DataTable();
componentDbs.Columns.Add("ComponentDbID", typeof(Int32));
componentDbs.Columns.Add("ComponentID", typeof(Int32));
componentDbs.Columns.Add("DbServerID", typeof(Int32));
componentDbs.Columns.Add("EntityID", typeof(int));
componentDbs.Columns.Add("SecurableGuid", typeof(String));
componentDbs.Columns.Add("FriendlyName", typeof(String));
componentDbs.Columns.Add("DbName", typeof(String));
componentDbs.Rows.Add(new object[] { 1, 2, 2, 3822, "SecureableGuid", "Test #1", "DB #1" });
return componentDbs;
}
public DataRow GetComponentDb(int id)
{
DataTable componentDbs = new DataTable();
componentDbs.Columns.Add("ComponentDbID", typeof(Int32));
componentDbs.Columns.Add("ComponentID", typeof(Int32));
componentDbs.Columns.Add("DbServerID", typeof(Int32));
componentDbs.Columns.Add("EntityID", typeof(Int32));
componentDbs.Columns.Add("SecurableGuid", typeof(String));
componentDbs.Columns.Add("FriendlyName", typeof(String));
componentDbs.Columns.Add("DbName", typeof(String));
componentDbs.Rows.Add(new object[] { 123, 121, 12, null, "SecurableGuid", "Name", "Database name" });
return componentDbs.Rows[0];
}
PersistComponentDb
后面的其余代码是
public int PersistComponentDb(ComponentDbModel componentDb)
{
// Example implementation.
return _repository.PersistComponentDb(componentDb);
}
和
int PersistComponentDb(ComponentDbModel componentDb);
答案 0 :(得分:1)
这种方法自称。因此堆栈溢出。
public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
return PersistComponentDb(componentDb);
}
这段代码应该是:
public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
return _repository.PersistComponentDb(componentDb);
}