title: Substitute for Group_Concat to customize existing Entity Framework model
body: <p>I'm using a many-to-many database with join tables connecting main data tables through foreign keys.</p>
  <p><a href="http://img12.imageshack.us/img12/6500/databasew.png" rel="nofollow noreferrer">http://img12.imageshack.us/img12/6500/databasew.png</a></p>
  <p>With my data representation, it's required to concatenate several rows of subordinate table fields (e.g. Genres.name) into one cell of the databound grid.</p>
  <p>Book Title |         Genres</p>
  <p>Some Book  | fiction; horror; mystery</p>
  <hr />
  <p>With the dataset I used this SQL query with GROUP_CONCAT for this purpose:</p>
  <pre><code>SELECT Books.ID, Books.BOOKTITLE, GROUP_CONCAT(Genres.name, '; ') As Gen
  
  FROM   Books INNER JOIN
  
         Books_Genres ON Books.ID = Books_Genres.book_id INNER JOIN
         Genres ON Books_Genres.genre_id =Genres.id
  
  GROUP BY Books.ID
  </code></pre>
  <p>As I'm now moving on to EF4 and being pretty new to it, I have no idea how to achieve the same resulting table that could be displayed in a datagrid with entities. What kind of changes should be made to the Entity model to get the same result?</p>
  <p>Any help greatly appreciated!</p>
  <hr />
  <p>Update:</p>
  <p>I have an entity model generated by database (Model1.edmx &amp; Model1.Designer.cs). Do I need to edit the Model1.edmx (xml file)? A few step by step instructions would greatly help. I'm just starting EF4, it's all Greek to me. :)</p>
  <p>I made a custom class:</p>
  <pre><code>public partial class Book {
          [EdmScalarProperty(EntityKeyProperty = false, IsNullable = true)]
          [DataMember()]
          public global::System.String GenresConcatenated
          {
              get { return string.Join(&quot;; &quot;, Genres.Select(g =&gt; g.name));}
              set {}
          }
          private List&lt;Genre&gt; Genres{ get; set; }
       }
  </code></pre>
  <p>Now I can access the property GenresConcatenated in IDE IntelliSense, but when I run the application it throws the error:</p>
  <blockquote>
  <p>The number of members in the conceptual type 'MyNamespace.Book' does
  not match with the number of members on the object side type
  'MyNamespace.Common.Book'. Make sure the number of members are the
  same.</p>
  </blockquote>
  <p>It looks like:</p>
  <blockquote>
  <p>... EntityDataSource does not support custom properties in the partial
  classes.  It only returns the entity that is in the model.
  <a href="https://stackoverflow.com/questions/4505749/binding-custom-property-in-entity-framework">(Binding custom property in Entity Framework)</a></p>
  </blockquote>
  <p>So I'm back to square one. :)</p>