none
Turn off tracking to get rid of Explicit construction of entity type ### in query is not allowed. RRS feed

  • Question

  • Hi,

    I have done some research on the infamous issue "Explicit construction of entity type ### in query is not allowed."  A post on stackoverflow mentioned that the C# design team thought that explicitly new-ing entity objects is confusing from the tracking perspective.  

    I attempted to get of rid of this exception by turning off object tracking by setting ObjectTrackingEnabled to false.  It didn't work.  Would you suggest a way for me to reuse the generated entity class definitions?

    Test case:

    from i in ManyColumnsEntities select new ManyColumnsEntity { Column1 = i.Column1 };

    ManyColumnsEntity is a table with many columns (100+) where this query desires only one.  Because ManyColumnsEntity is an "entity type", new-ing is not allowed.  I'd like to populate a list of  ManyColumnsEntity directly using data from the DB, without the intermediate AsEnumerable, or ToList type of trick.  There's no reason why this is not allowed when the data context is explicitly set to not to track objects.  

    Thanks.

    Candy

    Monday, May 6, 2013 2:19 PM

Answers