<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Entity SQL cannot materialize an entity if you select individual columns instead of selecting the entity</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2009 : Entity SQL cannot materialize an entity if you select individual columns instead of selecting the entity</description>
  <pubDate>Tue, 28 Apr 2026 16:35:12 -700</pubDate>
  <lastBuildDate>Tue, 11 Aug 2009 11:27:55 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=1420</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Entity SQL cannot materialize an entity if you select individual columns instead of selecting the entity : The solution was to use the Type...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1420&amp;PID=5149#5149</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=543" rel="nofollow">pk55</a><br /><strong>Subject:</strong> 1420<br /><strong>Posted:</strong> 11-Aug-2009 at 11:27am<br /><br /><P>The solution was to use the Type constructor.&nbsp; MSFT answered:</P><DIV>This is an expected behvaior with Entity Framework. When you use a SELECT VALUE entity SQL you are essentially selecting the entity as a whole, in other words the type is preserverd. When you write an entity SQL that has a list of projection, Entity Framework doesnt know that the values in the projection list are part of the entity. In these cases, it is assigned a default type of Edm.Row which translates to DbDataRecord in the O-Space. More info on the SELECT operator in eSQL at <a href="http://msdn.microsoft.com/en-us/library/bb399554.aspx" target="_blank"><FONT color=#0033cc>http://msdn.microsoft.com/en-us/library/bb399554.aspx</FONT></A><BR><BR>If you want to construct the entity again from a list of projection you can use the Type constructor in ESQL. More examples of using the type constructor is at <a href="http://msdn.microsoft.com/en-us/library/bb738526.aspx" target="_blank"><FONT color=#0033cc>http://msdn.microsoft.com/en-us/library/bb738526.aspx</FONT></A><BR></DIV><DIV>&nbsp;</DIV><DIV>I had tried the type constructore before:</DIV><DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT VALUE myEntity(u.myKey, u.myCounter) FROM myEntitySet as u<BR><BR>but that gets an error: 'myEntity' cannot be resolved into a valid type constructor.<BR><BR>I didn't realize you actually need the edm model name to prefix the entity type and when I tried this, it worked:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT VALUE <strong>myModelName</strong>.myEntity(u.myKey, u.myCounter) FROM myEntitySet as u</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Tue, 11 Aug 2009 11:27:55 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1420&amp;PID=5149#5149</guid>
  </item> 
  <item>
   <title>Entity SQL cannot materialize an entity if you select individual columns instead of selecting the entity : I posted this on the Entity Framework/ADO.Net...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1420&amp;PID=5140#5140</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=543" rel="nofollow">pk55</a><br /><strong>Subject:</strong> 1420<br /><strong>Posted:</strong> 10-Aug-2009 at 10:41am<br /><br />I posted this on the Entity Framework/ADO.Net forum as well since I think it's an EF problem and not DevForce but just in case it is or someone has seen this before, I'm posting it here as well.<DIV>&nbsp;</DIV><DIV>Entity Framework (.Net 3.5/Visual Studio 2008 SP1/SQL Server 2008) using DevForce&nbsp;RTW&nbsp;with&nbsp;Silverlight 3 using a PassThruESQLQuery.<BR><BR>I have an entity that has&nbsp;one key column (GUID) and a single scalar&nbsp;column (BIGINT) that have been mapped in the model from the database (nothing behind the scenes here).&nbsp; If I create an ESQL query like:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT VALUE u FROM myEntitySet as u<BR>the query result can be cast to the entity type correctly.&nbsp; If however, I specify the column names:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT u.myKey, u.myCounter FROM myEntitySet as u<BR>then the query is physically executed (I can see it in SQL Profiler) but Entity Framework throws this error:<BR><BR>The specified cast from a materialized 'System.Data.Objects.MaterializedDataRecord' type to the 'MyTestProject.myEntity' type is not valid.<BR>&nbsp;&nbsp; at System.Data.Common.Internal.Materialization.Translator.CheckedConvert&#091;TSource,TTarget&#093;(TSource value)<BR><BR>I've tried switching the order of the columns around; adding an "as" clause (u.myKey AS myKey); using VALUE ROW or just ROW but the issue persists.&nbsp; When I look at the generated T-SQL, I notice that a "SELECT 1 AS &#091;C1&#093;" is added to the ESQL query that specifies the columns so my result set ends up having three columns instead of two.&nbsp; I think this is confusing conversion from datarecord to entity:<BR><BR>SELECT <BR>1 AS &#091;C1&#093;, <BR>&#091;Extent1&#093;.&#091;my_key&#093; AS &#091;my_key&#093;, <BR>&#091;Extent1&#093;.&#091;totalCount&#093; AS &#091;totalCount&#093;<BR>FROM &#091;dbo&#093;.&#091;myEntity&#093; AS &#091;Extent1&#093;<BR><BR>If I just use SELECT VALUE u, it generates:<BR>SELECT <BR>&#091;Extent1&#093;.&#091;my_key&#093; AS &#091;my_key&#093;, <BR>&#091;Extent1&#093;.&#091;totalCount&#093; AS &#091;totalCount&#093;<BR>FROM &#091;dbo&#093;.&#091;myEntity&#093; AS &#091;Extent1&#093;<BR><BR>Any help would be appreciated.</DIV>]]>
   </description>
   <pubDate>Mon, 10 Aug 2009 10:41:00 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1420&amp;PID=5140#5140</guid>
  </item> 
 </channel>
</rss>