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

  • Question

  • I have the following code

    foreach (var obj in MyList)
      // BL
       // BL

    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)

    what do you think?

    Tsahi Bar

    Monday, April 7, 2014 6:14 AM


All replies

    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,

    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