title: Entity Framework on different project - saving?
body: <p>I have an established SQL Server database setup. I then generated an Entity Framework model in a Console Application to test some selecting, editing and adding to the database. All went well.</p>
  
  <p>I am now moving more towards my final physical design of my WinForms and WebApp. So, I have decided to do the project in separate projects. I moved the Entity Framework to a Data project, I created a Services project, and I still have my console app as a test application (All in the same solution).</p>
  
  <p>I have a ClassLib with data transfer objects to pass between my layers. So my GUI layer and Service layer don't know of the Entity Framework. I have helper methods in my EF project that convert the EF data into List etc...</p>
  
  <p>Eg of a helper method:</p>
  
  <pre><code>using ClassLib;
  
  namespace Data
  {
      public class PayeeDAL : EntityBase
      {
  
      public static List&lt;PayeeDto&gt; GetPayees()
      {
          var payees = (from payee in Db.payees
                        select payee).ToList();
  
          List&lt;PayeeDto&gt; reply = new List&lt;PayeeDto&gt;();
  
          foreach (var pa in payees)
          {
              PayeeDto p = new PayeeDto
                               {
                                   PayeeId = pa.payee_id,
                                   Name = pa.name,
                                   Deleted = pa.deleted == null
                               };
              reply.Add(p);
          }
          return reply;
  
      }
  }
  }
  </code></pre>
  
  <p>And my data transfer object looks like this:</p>
  
  <pre><code>namespace ClassLib
  {
      public class PayeeDto
      {
          public int PayeeId { get; set; }
          public string Name { get; set; }
          public bool Deleted { get; set; }
      }
  }
  </code></pre>
  
  <p>So, my selection is working well with this design... but...  have no idea how to handle saving.</p>
  
  <p>In my console application, when the EF was available to me, I did this:</p>
  
  <pre><code>                        db.AddToaccount_transaction(ac);
  
                      account_transaction_line atl = new account_transaction_line
                      {
                          amount = amount,
                          cost_centre =
                              db.cost_centre.FirstOrDefault(
                                  cc =&gt; cc.cost_centre_id == costcentreid),
                          sub_category =
                              db.sub_category.First(
                                  sc =&gt; sc.sub_category_id == subcategoryId),
                          account_transaction = ac,
                          budget = db.budgets.FirstOrDefault(b =&gt; b.budget_id == budgetid)
  
                      };
  
                      db.AddToaccount_transaction_line(atl);
  
  
                  }
  
  
  
                  db.SaveChanges();
  </code></pre>
  
  <p>But now I don't have access to .AddTo.... and .SaveChanges... In my Console app, I'd create a parent object, and then add a few child objects... and then add the child objects to the parent object, and save.</p>
  
  <p>But how would this be done in my new structure? I'm thinking I'd have a Save method in each of my helper classes... And then pass a List&lt;> of the child objects, along with a single Parent class to the save method... and then transfor the Dtos to EF models, and then save it that way?</p>
  
  <p>Is that an acceptable plan?</p>