Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd documentation to generated code in entity framework model first
    primarykey
    data
    text
    <p>I have been using Entity Framework model first since VS 2010. When I build my project, EF generates a Model.Designer.cs file containing all entities. This designer file also contains the documentation added to the entities in the EDMX file.</p> <p>When I created a new EF model first project in VS 2012, a Model.tt file is added to my EDMX file. This T4 template generates a single file for every entity in my model. Unfortunately, the documentation from the EDMX file is not used in the generated code.</p> <p>I really like having my model documented so IntelliSense shows up when using it. The only workaround I have found so far is remove the Model.tt and the generated class files and turning the code generation on my EDMX file back on. This reverts back to the behaviour I am used from VS 2010. However, I would prefer having a separate file per entity.</p> <p>Is there any way (preferably using VS tools and without having to modify any files that ship with VS) to include the documentation from the EDMX file in the generated single class files?</p> <p>Edit: To further illustrate my problem, here is a quick example.</p> <p>Let's say my model looks like this:<img src="https://i.stack.imgur.com/y6mUQ.png" alt="simple entity framework model"></p> <p>I have highlighted the part where I entered the documentation in the Properties window of the Id property.</p> <p>This is what the entity looks like in the EDMX file:</p> <pre><code> &lt;EntityType Name="Entity1"&gt; &lt;Key&gt; &lt;PropertyRef Name="Id" /&gt; &lt;/Key&gt; &lt;Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" &gt; &lt;Documentation&gt; &lt;Summary&gt;This is documentation for the ID property.&lt;/Summary&gt; &lt;/Documentation&gt; &lt;/Property&gt; &lt;/EntityType&gt; </code></pre> <p>The generated class (Entity1.cs) by Model.tt looks like this:</p> <pre><code>public partial class Entity1 { public int Id { get; set; } } </code></pre> <p>But when I turn on the code generation for my model, this is what the entity looks like in Model.Designer.cs:</p> <pre><code>/// &lt;summary&gt; /// No Metadata Documentation available. /// &lt;/summary&gt; [EdmEntityTypeAttribute(NamespaceName="Model1", Name="Entity1")] [Serializable()] [DataContractAttribute(IsReference=true)] public partial class Entity1 : EntityObject { #region Factory Method /// &lt;summary&gt; /// Create a new Entity1 object. /// &lt;/summary&gt; /// &lt;param name="id"&gt;Initial value of the Id property.&lt;/param&gt; public static Entity1 CreateEntity1(global::System.Int32 id) { Entity1 entity1 = new Entity1(); entity1.Id = id; return entity1; } #endregion #region Simple Properties /// &lt;summary&gt; /// This is documentation for the ID property. /// &lt;/summary&gt; [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [DataMemberAttribute()] public global::System.Int32 Id { get { return _Id; } set { if (_Id != value) { OnIdChanging(value); ReportPropertyChanging("Id"); _Id = StructuralObject.SetValidValue(value, "Id"); ReportPropertyChanged("Id"); OnIdChanged(); } } } private global::System.Int32 _Id; partial void OnIdChanging(global::System.Int32 value); partial void OnIdChanged(); #endregion } </code></pre> <p>So you see: Model.Designer.cs contains my custom documentation string "This is documentation for the ID property." while Entity1.cs does not. However, Model.Designer.cs can get quite big if there are many entities and debugging into this file is somewhat slow. I'd prefer having several small files (one per entity), but still preserve the documentation from the EDMX file in the generated code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload