Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Though I don't know exactly why I bet that the entity framework doesn't like selecting <code>new</code> objects of the same type in the property you are writing your query off of. If my assumption is correct the following code should be equivalent to what you are trying to do:</p> <pre><code>public ActionResult Test() { using (MyEntities db = new MyEntities()) { var model = from c in db.Categories; return View(model.ToList()); } } </code></pre> <p>You would only need to select new objects when you are mapping the properties of your context's classes to another class (IE not one that is generated by the EF).</p> <p>I did a little more research into the issue, including duplicating it myself, according to the stack trace this is where the exception is thrown: <code>System.Data.Objects.ELinq.ExpressionConverter.CheckInitializerType(Type type)</code> Here is the source code for <code>CheckInitializerType</code> (<a href="http://reflector.webtropy.com/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/DataEntity/System/Data/Objects/ELinq/ExpressionConverter@cs/1305376/ExpressionConverter@cs" rel="nofollow">found here</a>):</p> <pre><code> // Determines whether the given type is supported for materialization private void CheckInitializerType(Type type) { // nominal types are not supported TypeUsage typeUsage; if (_funcletizer.RootContext.Perspective.TryGetType(type, out typeUsage)) { BuiltInTypeKind typeKind = typeUsage.EdmType.BuiltInTypeKind; if (BuiltInTypeKind.EntityType == typeKind || BuiltInTypeKind.ComplexType == typeKind) { throw EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_UnsupportedNominalType( typeUsage.EdmType.FullName)); } } // types implementing IEnumerable are not supported if (TypeSystem.IsSequenceType(type)) { throw EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_UnsupportedEnumerableType( DescribeClrType(type))); } } </code></pre> <p>For reasons I haven't determined yet, if the object you are trying to project properties onto has the <code>BuiltInTypeKind</code> of <code>EntityType</code> or <code>ComplexType</code>, then projection is not supported. With my testing I discovered that I can project properties onto an entity that was generated with another <code>edmx</code> file, so the relationship with a given <code>ObjectContext</code> seems to boil down to the <code>System.Data.Objects.DataClasses.EdmEntityTypeAttribute</code> that decorates the generated Entity class.</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. VO
      singulars
      1. This table or related slice is empty.
    2. 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