1

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);

7
  • @PrestonGuillot I'm guessing it's a typo and the new shouldn't be there. Commented Jun 3, 2015 at 17:06
  • @PrestonGuillot you are correct, I was trying it out right before I posted this. I have edited to what it is. Commented Jun 3, 2015 at 17:08
  • 1
    What is PersistCompnentDB suppose 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. Commented Jun 3, 2015 at 17:11
  • @juharr 'PersistComponentDB' is suppose to update and save into the "database", 'int PersistComponentDb(ComponentDbModel componentDb);' and ' public int PersistComponentDb(ComponentDbModel componentDb) { // Example implementation. return _repository.PersistComponentDb(componentDb); }' is the rest of the code that is behind 'PersistComponentDb' Commented Jun 3, 2015 at 17:16
  • 1
    Well retrun _repository.PersistComponentDb(componentDb); would work since that calls a similarly named method on a different object. Do you have a variable called _repository? Commented Jun 3, 2015 at 17:18

1 Answer 1

2

this method is calling itself. hence the stackoverflow.

public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
    return PersistComponentDb(componentDb);
}

should this code be:

public int PersistComponentDb(Core.Models.ComponentDbModel componentDb)
{
    return _repository.PersistComponentDb(componentDb);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.