I am fairly new to repositories and mock repositories, so I would like help understanding what this error means exactly and how to avoid it. I have looked at other posts and done my research but they are too specific to their errors. The code that is breaking is
public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
return PersistComponentDb(componentDb);
}
I understand that the function is calling itself but how do I stop it from doing that? It is persisting a mock repository, and the hard coded values look like this
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];
}
The rest of the code that is behind PersistComponentDb is
public int PersistComponentDb(ComponentDbModel componentDb)
{
// Example implementation.
return _repository.PersistComponentDb(componentDb);
}
and
int PersistComponentDb(ComponentDbModel componentDb);
newshouldn't be there.PersistCompnentDBsuppose to do? I'm not sure this should even be a recursive call, but if it is you need a base case and you should be breaking down the problem into similar sub problems. So there should be at least one return that doesn't make a recursive call and the recursive call(s) should not be identical to the original call.retrun _repository.PersistComponentDb(componentDb);would work since that calls a similarly named method on a different object. Do you have a variable called_repository?