title: Entity Framework stored procedure results mapping
body: <p>I've looked for a similar topic to my question over the internet for the past few days. I finally resorted to asking this question myself.  </p>
  
  <p>Using code-first methodology and EF 4.3.1 I created a context class, entity classes, and classes to store the stored procedure output. The context class has methods that execute certain stored procedures using <code>SqlQuery&lt;T&gt;</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>public IEnumerable&lt;Results&gt; GetData(int id)
  {
     var parameters = new SqlParameter[] { new SqlParameter("@id", id) };
     var result = this.Database.SqlQuery&lt;Result&gt;("Exec dbo.sproc_GetData @id",    parameters);
     var data= result.ToList&lt;Result&gt;();
  
     return data;
  }
  </code></pre>
  
  <p>As I am tracing my debug my data comes back, and data is mapped to properties with a matching name. However, in the output there is a column with a <code>"/"</code> in the name (example: <code>Info/Data</code>).  Obviously I can't name a property like that so I figured I could map the output using the column attribute (<code>[Column("Info/Data")]</code>) :</p>
  
  <pre><code>[Column("Info/Data")]
  public string InfoData
  {
     get { return infoData; }
     set { infoData= value; }
  }
  </code></pre>
  
  <p>I even tried using the verbatim operator (<code>[Column(@"Info/Data")]</code>), wrapping the text with <code>[]</code> (<code>[Column("[Info/Data]")]</code>), and I tried both (<code>[Column(@"[Info/Data]")]</code>). When stepping through the code I see that properties with matching column names are assigned, but properties with the column attribute are ignored and stepped over during assignment.</p>
  
  <p>I also tried fluent-api for every column for the entity.</p>
  
  <pre><code>    modelBuilder.ComplexType&lt;Result&gt;().Property(d =&gt; d.InfoData).HasColumnName("Info/Data");
  </code></pre>
  
  <p>but that throws the following exception:</p>
  
  <blockquote>
    <p>The data reader is incompatible with the specified 'NameSpace.Result'. A member of the type, 'InfoData', does not have a corresponding column in the data reader with the same name.</p>
  </blockquote>
  
  <p>In my project <code>NameSpace.Result</code> is a class (name changed for security) and <code>InfoDatais</code> is the property that I try to map using fluent-api (the corresponding sql column has a / in it; ex: Info/Data).</p>
  
  <p>Has anyone ran into this issue? </p>
  
  <p>If my problem isn't clear or it's been asked before please let me know.</p>