Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating EF controls in MVC with enums as keys
    primarykey
    data
    text
    <p>Ok so here's some context: I'm using EF5, MVC4 and SQL CE4 to build up a web application. I've been loosely following this <a href="http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4" rel="nofollow noreferrer">tutorial</a> with a few differences. </p> <ol> <li>My context class and POCO objects are in their own assembly.</li> <li>I'm using SQL CE4 instead of SQL Express Local DB</li> <li>My classes aren't as simple as the tutorial</li> </ol> <p>I've already used a <a href="https://stackoverflow.com/questions/12165185/mvc4-scaffolding-add-controller-gives-error-unable-to-retrieve-metadata/14576216#14576216">workaround</a> to get simple classes to work register.</p> <p>I had thought using enums in EF5 was <a href="http://msdn.microsoft.com/en-us/data/hh859576.aspx" rel="nofollow noreferrer">supported</a> in EF5, but can they be used in Keys?</p> <p>When I try to <strong>add a control</strong> (Add Controller, MVC controller with read/write actions and views, using Entity Framework) for a simple class (1 int key property, 1 string property), it works. I get varied errors when trying to add a class that has a property which is part of a key (primary or foreign)</p> <pre><code>Unable to retrieve metadata for 'blah'. Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used. Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index C:\Program Files (x86)\Microsoft Visual Studio\11.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\ CodeTemplates\AddController\ControllerWithContext.tt(0,0) : error : Running transformation: System.IndexOutOfRangeException: Index was outside the bounds of the array. ---StackTrace--- </code></pre> <p>The only similarities I've found between these classes is that they have an emun that's tied to a key. Other classes with non-key enums generate correctly. Is this the issue or have I completely missed the mark?</p> <p>Edit: Example of a class which fails</p> <pre><code>public class A { public virtual AIdEnum Id { get; set; } public virtual string Name { get; set; } public virtual ICollection&lt;B&gt; Bs { get; set; } public virtual ICollection&lt;C&gt; Cs { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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