title: Linq to Entity - Inserting a record
body: <p>I am new to Linq to Entity (Infact I am new to Linq) and I am struggling to insert a row.</p>
  
  <p>Following a number of tutorials (None of which seem to agree with each other or are very detailed) I managed to come up with the following code but I'm struggling to work out how to use what I have ... </p>
  
  <p>The DB looks like this: </p>
  
  <pre><code>namespace IdeaGen.Data
  {
  using System;
  using System.Data.Entity;
  using System.Data.Entity.Infrastructure;
  
  public partial class IdeaGenEntities : DbContext
  {
      public IdeaGenEntities()
          : base("name=IdeaGenEntities")
      {
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          throw new UnintentionalCodeFirstException();
      }
  
      public DbSet&lt;Idea&gt; Ideas { get; set; }
      public DbSet&lt;User&gt; Users { get; set; }
  }
  }
  </code></pre>
  
  <p>My model looks like this: </p>
  
  <pre><code>public class NewIdea
  {
      public int IdeaID { get; set; }
      public string Title { get; set; }
      public string Description { get; set; }
      public int UserID { get; set; }
  }
  </code></pre>
  
  <p>(I haven't done the user model yet)</p>
  
  <p>And my controller looks like this but isn't compiling. </p>
  
  <pre><code>using (IdeaGenEntities ctx = new IdeaGenEntities())
          {
              var ideas = ctx.Ideas;
              NewIdea idea = new NewIdea();
              idea.Description = model.Description;
              idea.Title = model.Title;
              ctx.Ideas.Add(idea);
              ctx.SaveChanges();
          }
  </code></pre>
  
  <p>Oh and I also use this as per one of the tutorials ... </p>
  
  <pre><code>namespace IdeaGen.Data
  {
  public class DBBase
  {
      private IdeaGenEntities _IdeaGenEntity = new IdeaGenEntities();
  
      public IdeaGenEntities IdeaGenEntity {get {return _IdeaGenEntity; } }
  }
  }
  </code></pre>
  
  <p>Could anyone point me in the right direction? Once I get a foundation understanding of what I am doing I will be able to work the rest out but with nothing to work from I am kinda in the dark about where I have gone wrong. </p>
  
  <p>Thanks in advance</p>
  
  <p>Edit: </p>
  
  <p>Got it thanks to user user619656. My updated Controller looks like this ... </p>
  
  <pre><code>        IdeaGenEntities ctx = new IdeaGenEntities();
          Idea Idea = new Idea();
          Idea.Title = model.Title;
          Idea.Description = model.Description;
          ctx.Ideas.Add(Idea);
          ctx.SaveChanges();
  </code></pre>
  
  <p>Thanks for your help</p>