none
How to implement Save in an in-memory repository RRS feed

  • Question

  • I have the following code

    foreach (var obj in MyList)
    {
      // BL
      repository.Add(obj)
       // BL
      repository.Update(obj)
    }

    I have two classes that implement IRepository. One class uses MsSql and one in-memory. the in-memory implementation uses List to store my data. If I use the MsSql class then all the data is already stored in DB. If I use the in-memory then I need to insert all the data from the repository's list to DB after the foreach loop. I'm not sure what is the best way to do this OOP wise.

    I can add a Save method to IRepository but that means that the MsSql class will implement a method that it doesn't need. Another option is to add a method only in the in-memory class and to do something like this:

    IRepository rep = repository as InMemoryRepository
    if (rep != null)
    {
        rep.Save()
    }

    what do you think?


    Tsahi Bar

    Monday, April 7, 2014 6:14 AM

Answers

All replies

  • http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
    Friday, April 11, 2014 5:09 AM
  • Hi,

    Thank you for visiting the MSDN forum.

    I'm afraid that it is not the correct forum about this issue, since this forum is to discuss Visual Basic. I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.

    Thanks for your understanding.

    Best regards,
    Franklin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 14, 2014 2:02 AM