Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Indices are not supported natively, but if you head to the "Influencing the DDL Generation" section of <a href="http://msdn.microsoft.com/en-us/data/ff830362.aspx" rel="nofollow">this</a> article you can see how to add this custom functionality to an existing template.</p> <p>In the article's example, the new index in your EDMX's CSDL would look something like this:</p> <pre><code>&lt;Property ... &gt; &lt;myExtensions:Index indexName="Seat" edmx:CopyToSSDL="true"/&gt; &lt;/Property&gt; </code></pre> <p>But to get this working you would have to modify a few things (see the link I provided for the details). Firstly, you'd have to declare that "myExtensions" namespace on the schema node:</p> <pre><code>&lt;!-- CSDL content --&gt; &lt;edmx:ConceptualModels&gt; &lt;Schema [...] xmlns:myExtensions="http://www.microsoft.com/userExtensions"&gt; [...] &lt;/edmx&gt; </code></pre> <p>Secondly, you'd have to modify the template found at:</p> <blockquote> <p>\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt</p> </blockquote> <p>The solution requires Linq, so add this to the top of the template:</p> <pre><code>&lt;#@ assembly name="System.Xml.Linq" #&gt; </code></pre> <p>And then add this to the bottom:</p> <pre><code>-- Creating index for table based on custom extensions -- &lt;# foreach (EntitySet entitySet in Store.GetAllEntitySets()) { string tableName = Id(entitySet.GetTableName()); string schemaName = Id(entitySet.GetSchemaName()); EdmProperties props = entitySet.ElementType.Properties; foreach (EdmProperty ep in props.Where(p =&gt; p.TypeUsage.EdmType is PrimitiveType)) { MetadataProperty meta = ep.MetadataProperties.FirstOrDefault(mp =&gt; mp.Name == "http://www.microsoft.com/userExtensions:Index"); if (meta != null) { System.Xml.Linq.XElement e = meta.Value as System.Xml.Linq.XElement; System.Xml.Linq.XAttribute attr = e.Attributes().FirstOrDefault(a =&gt; a.Name == "indexName"); string indexName = attr.Value; // create an index for specified column #&gt; CREATE INDEX [IX_&lt;#=indexName#&gt;] ON &lt;#if (!IsSQLCE) {#&gt;[&lt;#=schemaName#&gt;].&lt;#}#&gt;[&lt;#=tableName#&gt;] ([&lt;#=indexName#&gt;]); &lt;# } } } #&gt; </code></pre> <p>Most of that could be pretty easily modified to fit your needs. The article goes into more of the details, but the most important line in the above code is the one which fetches that custom "Index" extension node:</p> <pre><code>MetadataProperty meta = ep.MetadataProperties.FirstOrDefault(mp =&gt; mp.Name == "http://www.microsoft.com/userExtensions:Index"); </code></pre> <p>Hope that helps!</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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