title: How do I correctly separate the database operations from the gui/logic in c# when working with datasources?
body: <p>Im having a really hard time figuring out how to specify a good search term for my problem: separation of gui and database interaction in visual studio 2008 using Linq to sql.</p>
  
  <p>According to my teacher in a c# class im taking it's not correct to let the GUI be dependant on a specific way of getting data.</p>
  
  <p>The way my project is currently set up is that we have a mssql database where everything is stored.
  The solution is split into 4 seperate projects. UserGUI, AdminGUI, Logic and Db.</p>
  
  <p>Now using linq to populate listboxes and similar things I use something like:</p>
  
  <p>From the windows form in the project UserGUI:</p>
  
  <pre><code>//The activeReservationBindingSource has Db.ActiveReservation as it's value
  private void refreshReservation() {
              activeReservationBindingSource.DataSource = logic.getActiveReservationsQry();
          }
  </code></pre>
  
  <p>To the Logic project:</p>
  
  <pre><code>public IQueryable getActiveReservationsQry() {
      return dbOperations.getActiveReservationsQry(this.currentMemberId);
  }
  </code></pre>
  
  <p>To the database project:</p>
  
  <pre><code>public IQueryable getActiveReservationsQry(int memberId) {
              var qry =
               from active in db.ActiveReservations
               where active.memberId == memberId
               orderby active.reservationId
               select active;
  
              return qry;
          }
  </code></pre>
  
  <p>This makes sense to me seing as I can send items from listboxes all the way to the database project and there easily update/insert things into the mssql database. The problem is that it would be pretty hard to merge over from a mssql database to lets say an access version.</p>
  
  <p>What should I be reading up on to understand how to do this correctly? Is creating my own classes with the same values as the ones visual studio generates for me when I create the dbml file a way to go? Should I then in the logic project populate for example List that I pass to the GUI? To me it seams like "double work" but perhaps it's the correct way to go? </p>
  
  <p>Be adviced that we have not read anything about design patterns or business logic which seems to be a pretty big subject which im looking forward to exploring outside the frame of the course at a later time.</p>
  
  <p>I was also thinking that IQueryable inherits from IEnumerable and perhaps that was the way to go but I have failed to find any information that made sense to me on how to actually accomplish this.</p>
  
  <p>The GUI also knows about the datasources which I think is a bad thing but can't figure out how to get rid of.</p>
  
  <p>Please understand that I tried to figure this out with my teacher for half an hour today at the only tutoring available for this project and then spent most of the day trying to find similar answers on google, SO and from classmates without any result.</p>