title: Serialization issue with entity framework and sql session state
body: <p>I have this entity and dbcontext on my application:</p>
  
  <pre><code>[Serializable, Table("calc.Student")]
  public class Student
  {
      public int Id { get; set; }
  }
  
  public StudentDbContext() : base("name=DefaultConnection") 
  { 
  
  }
  
  public DbSet&lt;Student&gt; Students { get; set; }
  
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
  }
  </code></pre>
  
  <p>My DTO class:</p>
  
  <pre><code>[Serializable]
  public class StudentDTO
  {
      public int Id { get; set; }
  }
  </code></pre>
  
  <p>My api controller:</p>
  
  <pre><code>public IQueryable&lt;StudentDTO&gt; Get()
  {
      var students = from b in db.Students
                     select new StudentDTO()
                     {
                         Id = b.Id
                     };
      return students ;
  }
  </code></pre>
  
  <p>Now my problem here is with my session state. On my web.config file, I stated the code below so I can store my session on the database:</p>
  
  <pre><code>&lt;sessionState mode="SQLServer" allowCustomSqlDatabase="true" cookieless="false"
  </code></pre>
  
  <p>With this line of code, I am receiving this error:</p>
  
  <blockquote>
    <p>Unable to serialize the session state. In 'StateServer' and
    'SQLServer' mode, ASP.NET will serialize the session state objects,
    and as a result non-serializable objects or MarshalByRef objects are
    not permitted. The same restriction applies if similar serialization
    is done by the custom session state store in 'Custom' mode.</p>
  </blockquote>
  
  <p>I thought returning a DTO object would resolve my problem but now I am stuck.</p>
  
  <p>Any ideas?</p>