<?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 : Lazy-Loaded BLOB Property</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Lazy-Loaded BLOB Property</description>
  <pubDate>Sat, 11 Apr 2026 12:14:47 -700</pubDate>
  <lastBuildDate>Thu, 22 Apr 2010 16:45:57 -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=1723</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>Lazy-Loaded BLOB Property :  NEW &amp;#034;TABLE SPLITTING&amp;#034;...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6605#6605</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 22-Apr-2010 at 4:45pm<br /><br /><DIV></DIV><DIV><strong><FONT color=#ff0000 size=4>NEW "TABLE SPLITTING" ANSWER </FONT></strong></DIV><DIV>&nbsp;</DIV><DIV>I just learned about a new feature in Entity Framework v.4 called "Table Splitting".</DIV><DIV>&nbsp;</DIV><DIV>It isn't the lazy property we really want but it gives us a foundation for a decent simulation of lazy property ... and it works now, with DevForce 2010.</DIV><DIV>&nbsp;</DIV><DIV>Btw, Danny Simmons (EF Team) says they wanted to get Lazy Property into EF 4 ... and ran out of time. At least it's on their roadmap.</DIV><DIV>&nbsp;</DIV><DIV><strong>Table Splitting</strong></DIV><DIV>&nbsp;</DIV><DIV>Apparently EF always had the ability to map two entities to the same table, "splitting" the columns/properties between the two. </DIV><DIV>&nbsp;</DIV><DIV>They called it "Table Splitting", not to be confused with "Entity Splitting" ... which is when a single entity is mapped to two separate tables. "Table Splitting" and "Entity Splitting" are opposites. Just try&nbsp;to remember which is which :-)</DIV><DIV>&nbsp;</DIV><DIV><DIV>&nbsp;</DIV><DIV>In our example of "Table Splitting", we create an Employee entity (with properties mapped to every column EXCEPT photo) and an EmployePhoto entity (with two properties, EmployeeID and Photo, mapped appropriately).</DIV><DIV>&nbsp;</DIV></DIV><DIV>I said earlier that EF didn't support this trick. I wasn't entirely right about that. Apparently EF v.1 supported it. Unfortunately, the EF Designer did not and would refuse to validate the model. This circumstance parallels EF v.1's support for complex types; yes, they were there ... but the Designer threw a fit if you tried to use it.</DIV><DIV>&nbsp;</DIV><DIV>You can read all about "Table Splitting" ... and how to do it ... from Gil Fink here: <P style="MARGIN: 0in 0in 0pt" =Mso><a href="http://blogs.microsoft.co.il/blogs/gilf/archive/2009/10/13/table-splitting-in-entity-framework.aspx" target="_blank"><U><FONT size=3 face=C&#111;nsolas>http://blogs.microsoft.co.il/blogs/gilf/archive/2009/10/13/table-splitting-in-entity-framework.aspx</FONT></U></A><FONT size=3 face=C&#111;nsolas> </FONT></P></DIV><DIV>&nbsp;</DIV><DIV>Here's some example DevForce code to illustrate the point:</DIV><DIV>&nbsp;</DIV><DIV><P style="MARGIN: 0in 0in 0pt" =Mso><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>void&nbsp;GetEmployeesWithLazyPhoto {</P><DIV></FONT></FONT><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes"></SPAN></FONT></FONT>&nbsp;</DIV><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>var em = new NorthwindIBEntities();</DIV><DIV></FONT></FONT><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes"></SPAN></FONT></FONT>&nbsp;</DIV><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get first three employees ... without their photos</SPAN></FONT></FONT></DIV><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>var emps= em.Employees.Take(3).ToList();</FONT></FONT></DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes"><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes"></SPAN></FONT></FONT><FONT size=2 face=Verdana>&nbsp;</FONT></DIV><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Prove that we did not get the EmployeePhoto entities at the same time</SPAN></FONT></FONT></DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>var&nbsp;photos = em.EmployeePhotos.With(QueryStrategy.CacheOnly).ToList();</DIV><DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Diagnostics.Debug.Assert(!photos.Any()); // there aren't any photos</DIV><DIV></FONT></FONT><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes"></SPAN></FONT></FONT>&nbsp;</DIV><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get the photo of the first employee</SPAN></FONT></FONT></DIV><DIV><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>var&nbsp;firstPhoto = emps.First().EmployeePhoto;</FONT></FONT></DIV><P style="MARGIN: 0in 0in 0pt" =Mso><?: prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT size=3 face=C&#111;nsolas>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Diagnostics.Debug.Assert(</FONT></o:p></P><P style="MARGIN: 0in 0in 0pt" =Mso><o:p><FONT size=3 face=C&#111;nsolas>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !firstPhoto.EntityAspect.IsNullEntity);// now we have it</FONT></o:p></P><P style="MARGIN: 0in 0in 0pt" =Mso><o:p>&nbsp;</o:p><FONT size=3><FONT face=C&#111;nsolas><SPAN style="mso-spacerun: yes"> </SPAN>}</FONT><FONT size=2 face=Verdana> </P><DIV></DIV><DIV></DIV><DIV></DIV><DIV></DIV><DIV>&nbsp;</DIV><DIV>---</DIV><DIV>Notes:</DIV><DIV>&nbsp;</DIV><DIV>(1) Yes, you can use INCLUDE to get the photos eagerly with the Employees:</DIV><DIV>&nbsp;</DIV><DIV><FONT size=3 face=C&#111;nsolas>&nbsp;&nbsp; var emps= em.Employees.Include("EmployeePhoto").Take(3).ToList();</FONT></DIV><DIV>&nbsp;</DIV><DIV>(2) Employee must be the "principal" entity and EmployeePhoto must be the "dependent" entity to ensure that a new Employee is always inserted before EmployeePhoto. You'll get that arrangement if you follow Mr. Fink's recipe.</DIV><DIV>&nbsp;</DIV><DIV>I've tested the query. I&nbsp;haven't tested adding new Employees or EmployeePhotos. This note is more of a prediction than a prescription.&nbsp;I'm not sure what happens if you try to add a new EmployeePhoto before adding its Employee. </DIV><DIV>&nbsp;</DIV><DIV>(3) If you want to be able to create new Employee objects, the Photo column in the Employee table&nbsp;must either be nullable or have a database default value. Entity Framework has to be able to insert a new Employee table row without specifying a value for the Photo column. Nothing new here ... just good old SQL.</DIV><DIV>&nbsp;</DIV><DIV>(4) The entity referential integrity check should take care of deleting the EmployeePhoto when you delete the parent Employee. Haven't confirmed yet.&nbsp; Of course deleting the Employee effectively deletes the EmployeePhoto regardless ... because deleting the table row deletes both.&nbsp; </DIV><DIV>&nbsp;</DIV><DIV>I do not know yet what happens if you try to delete EmployeePhoto. Presumably the Referential Integrity check will prevent this.</DIV><DIV>&nbsp;</DIV><DIV>The net of these considerations is that you should hide them all from Employee consumers. You don't want them worrying about this stuff. You want them to think of the photo as part of the Employee ... not as another entity.</DIV><DIV>&nbsp;</DIV><DIV>If you don't need to search for Photos independent of the Employee (and why would you?), I would try to make the EmployeePhoto entity&nbsp;internal to the domain model assembly.</DIV><DIV>&nbsp;</DIV><DIV>&#091;Again, haven't tried this yet either. Thinking out loud.&#093;</DIV><DIV>&nbsp;</DIV><DIV>Of course that means no consumer would ever see the EmployeePhoto entity. That's just fine. I'd make the Employee.EmployeePhoto navigation property internal as well&nbsp;or maybe private. </DIV><DIV>&nbsp;</DIV><DIV>I'd create a public Photo class (if necessary). I'd add a custom Photo property for Employee, implemented such that it used the non-public EmployeePhoto property to acquire the photo and poured the photo bytes into an instance of the Photo class; this Photo class instance, not the EmployeePhoto entity, is what I'd return to the caller.</DIV><DIV>&nbsp;</DIV><DIV>I'd also bury the mechanics of making a new EmployeePhoto inside this custom Employee.Photo property. Or maybe I'd create Employee.AddPhoto, Employee.UpdatePhoto, and Employee.DeletePhoto methods instead. It's up to you. The point is to encapsulate the mess.</DIV><DIV>&nbsp;</DIV><DIV>Now it may be that&nbsp;the&nbsp;caller can no longer compose&nbsp;the query that eagerly loads EmployeePhotos with&nbsp;their employees&nbsp;(see Note #1). </DIV><DIV>&nbsp;</DIV><DIV>I haven't tried this yet (as I keep saying). If so, that's fine with me. If I want eager photo loading, I should cover the query in my Repository class which DOES have access to the internal EmployeePhoto entity. I don't want outsiders to&nbsp;see me making sausage.</DIV><DIV>&nbsp;</DIV><DIV><EM>You do have a Repository class, right? You don't let your UI query all by itself do you? That's not good design. Once you start thinking seriously about how and when to expose entities, you'll know that you want to encapsulate all the persistence machinery - including DevForce persistence machinery - in a Repository or "DataService" class.</EM></DIV><DIV>&nbsp;</DIV><DIV>For the last time, I haven't tried these refinements yet. I'm broaching them in case you want to be a pioneer.</DIV><DIV>&nbsp;</DIV></FONT></FONT></DIV>]]>
   </description>
   <pubDate>Thu, 22 Apr 2010 16:45:57 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6605#6605</guid>
  </item> 
  <item>
   <title>Lazy-Loaded BLOB Property : The lazy property feature is not...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6573#6573</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 21-Apr-2010 at 12:18am<br /><br /><P>The lazy property feature is not presently on the near term schedule (although this conversation has certainly got my attention).</P><DIV>I'd like to help you work through to something that is satisfactory.</DIV><DIV>&nbsp;</DIV><DIV>How many of these overstuffed tables do you have :-) ?</DIV><DIV>Which of my "possible solutions" did you have in mind?</DIV><DIV>&nbsp;</DIV><DIV>We should take this out of the forum I think. Please contact me at <a href="mailto:AskWard@ideablade.com" target="_blank">AskWard@ideablade.com</A></DIV>]]>
   </description>
   <pubDate>Wed, 21 Apr 2010 00:18:50 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6573#6573</guid>
  </item> 
  <item>
   <title>Lazy-Loaded BLOB Property : Hi Ward,  Unfortunately option...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6570#6570</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=746" rel="nofollow">kshaban</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 20-Apr-2010 at 10:22pm<br /><br />Hi Ward,<DIV>&nbsp;</DIV><DIV>Unfortunately option 1 is not feasible due to this being an existing 3.5 app built on top of Linq to SQL (which BTW does support lazy-properties through DelayValue&lt;T&gt; backing fields)</DIV><DIV>&nbsp;</DIV><DIV>The existing model has many delayed blobs and text properties.&nbsp; Our "version" of Linq to SQL is a bit hacked up to provide future queries and the ability to&nbsp;do exactly like you alluded to with making view objects that are filled using projections.</DIV><DIV>&nbsp;</DIV><DIV>However, our view objects are fully live since we also manage state and identity management.&nbsp; We actually construct our own update and insert TSQL as well to conpensate for a lake of batching of update and insert statements by Linq to SQL.</DIV><DIV>&nbsp;</DIV><DIV>Of course, this being all said we did not want to build all this nor do we want to continue to maintain our own home grown ORM but would much rather transition to a full fledged framework with true N-tier support.</DIV><DIV>&nbsp;</DIV><DIV>What you referred to as possible solution, would it involve fully live view objects?</DIV><DIV>&nbsp;</DIV><DIV>If the lazy-property features are something in the pipeline I would be happy to beta test&nbsp;for you as well.</DIV><DIV>&nbsp;</DIV><DIV>Thanks,</DIV><DIV>&nbsp;</DIV><DIV>Kavan</DIV>]]>
   </description>
   <pubDate>Tue, 20 Apr 2010 22:22:49 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6570#6570</guid>
  </item> 
  <item>
   <title>Lazy-Loaded BLOB Property : It appears that at least two other...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6569#6569</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 20-Apr-2010 at 8:04pm<br /><br />It appears that at least two other ORMs support lazy loaded properties:<DIV>&nbsp;</DIV><DIV>NHibernate (<a href="http://ayende.com/Blog/archive/2010/01/27/nhibernate-new-feature-lazy-properties.aspx" target="_blank">http://ayende.com/Blog/archive/2010/01/27/nhibernate-new-feature-lazy-properties.aspx</A>) </DIV><DIV>&nbsp;</DIV><DIV>LLBLGen (<a href="http://www.llblgen.com/&#100;ocumentati&#111;n/2.6/hh_start.htm" target="_blank">http://www.llblgen.com/documentation/2.6/hh_start.htm</A>&nbsp;... says Franz; although I couldn't find the exact page I'm sure it's in there.)</DIV><DIV></DIV><DIV></DIV><DIV>&nbsp;</DIV><DIV>Kudos to both.</DIV><DIV>&nbsp;</DIV><DIV>As Ayende observes "This feature is mostly meant for unique circumstances, such as Person.Image, Post.Text, etc. As usual, be cautious in over using it."</DIV><DIV>&nbsp;</DIV><DIV>Amen to that.</DIV><DIV>&nbsp;</DIV><DIV>We'll get to it at some point (unless EF gets there first).</DIV>]]>
   </description>
   <pubDate>Tue, 20 Apr 2010 20:04:51 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6569#6569</guid>
  </item> 
  <item>
   <title>Lazy-Loaded BLOB Property : Hi Kavan -  I should have written...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6525#6525</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 19-Apr-2010 at 6:49pm<br /><br />Hi Kavan -<DIV>&nbsp;</DIV><DIV>I should have written this reply before the one above.</DIV><DIV>&nbsp;</DIV><DIV>We have long recognized that many people have big tables and would like to lazily load some of the properties. All the machinations I described could be hidden by a sufficiently powerful framework.</DIV><DIV>&nbsp;</DIV><DIV>I don't know a single Object Relational Mapping (ORM) framework that supports lazy properties. If you know of one, do&nbsp;tell.</DIV><DIV>&nbsp;</DIV><DIV>Why do you not see lazy properties in Entity Framework or anywhere else? Because it's hard. </DIV><DIV>&nbsp;</DIV><DIV>But we're in the business of "hard". We are going to add this feature some day.&nbsp; We've talked about it. We know how to do it. It's just a matter of priorities.</DIV><DIV>&nbsp;</DIV><DIV>W</DIV>]]>
   </description>
   <pubDate>Mon, 19 Apr 2010 18:49:50 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6525#6525</guid>
  </item> 
  <item>
   <title>Lazy-Loaded BLOB Property : Hi Kavan -     Great question...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6524#6524</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 19-Apr-2010 at 6:41pm<br /><br />Hi Kavan - <DIV>&nbsp;</DIV><DIV>&#091;<FONT color=#ff0000 size=4><strong>NEW "TABLE SPLITTING" ANSWER IN COMMENT BELOW</strong></FONT></DIV><DIV><FONT color=#ff0000 size=4><strong>&nbsp; keeping this answer intact for continuity / posterity&nbsp;</strong></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#093;</DIV><DIV>&nbsp;</DIV><DIV>Great question ... and one that troubles everyone who confronts a table with a blob in it ... whether you use DevForce, EF, ... another ORM ... raw ADO ... anything.</DIV><DIV>&nbsp;</DIV><DIV>The best answer is always the same: get that big blog OUT of the table. Move it out to another table. Then build a related entity mapped to that blob table to which you can navigate.</DIV><DIV>&nbsp;</DIV><DIV>Let's say you have an Employee and the Employee's Photo. Move the Photo out of the Employee table. If you're going to keep the photo in the database (not the only approach), put it in an EmployeePhoto table. Then you have an Employee entity that is trim and an EmployeePhoto entity which you fetch on demand (asynchronously one hopes).</DIV><DIV>&nbsp;</DIV><DIV>Whenever I see this question, I give this advice. When I give this advice, people either take it ... or they tell me that they can't.</DIV><DIV>&nbsp;</DIV><DIV>The only acceptable reason for taking my advice ... is if you have legacy code that depends upon the blob being there and you are truly stuck with that legacy code.</DIV><DIV>&nbsp;</DIV><DIV>Now I would fight like a cornered rat&nbsp;to escape this bind. I'd try to fake out the legacy code if I code. Maybe define a view and have the legacy code point to the view. All the better if the legacy code uses stored procedures to update the Employee. Then you split the table behind the scenes and no one is the wiser.</DIV><DIV>&nbsp;</DIV><DIV>If you are trapped,&nbsp;I will continue with some alternatives. But if there is any possible way of moving the blob out ... stop ... read no further ... please just do it.</DIV><DIV>&nbsp;</DIV><DIV>----</DIV><DIV>&nbsp;</DIV><DIV>Ok ... you're still reading ... which means that you're determined to keep the blob in the table.</DIV><DIV>&nbsp;</DIV><DIV>This will cost you. It will cost you in complexity if nothing else.&nbsp; Here we go.</DIV><DIV>&nbsp;</DIV><DIV><strong><FONT size=4>The Project + CUD Approach</FONT></strong></DIV><DIV>&nbsp;</DIV><DIV>You can separate the Query-for-Read code path from the Create/Update/Delete (CUD) code path.</DIV><DIV>&nbsp;</DIV><DIV>When you want Employees for presentation purposes, you issue a "projection" query that returns only the properties of Employee that you want to retrieve in a list.</DIV><DIV>&nbsp;</DIV><DIV><strong>Anonymous Type Query</strong></DIV><DIV>&nbsp;</DIV><DIV>Here' how you'd write a query to project Employee into an anonymous type</DIV><DIV>&nbsp;</DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp; var q1= EM.Employees</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Where(e =&gt; e.City == "Boston") // Example select</FONT></DIV><DIV><FONT face="Courier New"></FONT>&nbsp;</DIV><DIV><FONT face="Courier New">&nbsp; // Here comes&nbsp;the "projection"</FONT></DIV><DIV><FONT face="Courier New">&nbsp; var q2 = q1</FONT><FONT face="Courier New, Courier, mono">.<strong>Select(e =&gt; new {ID = e.ID, FirstName = e.FirstName, ...})</strong> // Everything but the photo</FONT></DIV><DIV><FONT face="Courier New, Courier, mono"></FONT>&nbsp;</DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp; // We'll use a synchronous queries for this example; you'd use async in the real world.&nbsp; </FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp; var emps = q2.ToList(); </FONT></DIV><DIV>&nbsp;</DIV><DIV>Unfortunately, "emps" is a list of some anonymous type. That's pretty hard to work with. </DIV><DIV>&nbsp;</DIV><DIV>You want a client-side type that is public, that you can talk about, potentially bind to. The type will be strictly read only ... you won't use it to for editing. It's simply a Data Transfer Object (DTO). </DIV><DIV>&nbsp;</DIV><DIV>Suppose we&nbsp;call it "EmployeeDto". We want to fill it on the Server-side and have DevForce move it over the wire for us. So we'll make it serializable. We'll write it as part of our Server project and link to it in our Silverlight project (I'm assuming Silverlight here):</DIV><DIV>&nbsp;</DIV><DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp; &#091;DataContract&#093;</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp; &#091;ReadOnly(true)&#093; // UI hint to make entire class ReadOnly<BR>&nbsp; public partial&nbsp;class EmployeeDto: IKnownType {</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &#091;DataMember&#093; public int ID { get; set; }</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp; &#091;DataMember&#093; public string FirstName { get; set; }<BR>&nbsp;&nbsp;&nbsp; // More core fields</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp; }</FONT></DIV></DIV><DIV><FONT face="Courier New, Courier, mono"><DIV>&nbsp;</DIV><DIV><FONT face="Arial, Helvetica, sans-serif">We rewrite our query like so:</FONT></DIV><DIV>&nbsp;</DIV><DIV>&nbsp; var q2 = q1<FONT face="Courier New, Courier, mono">.Select( e =&gt; </FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new EmployeeDto&nbsp;{</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID = e.ID, FirstName = e.FirstName, ...} // Everything but the photo</FONT></DIV><DIV><FONT face="Courier New, Courier, mono">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) </FONT></DIV><DIV><FONT face="Courier New, Courier, mono"></FONT>&nbsp;</DIV></FONT></DIV><DIV>Ok, now that&nbsp;you have EmployeeDtos, what do you do with them?&nbsp;You present them. </DIV><DIV>&nbsp;</DIV><DIV>How do you perform CUD operations? Not on the EmployeeDtos! When it's time to make changes, you work with whole Employee entities. </DIV><DIV>&nbsp;</DIV><DIV>Presumably, you'll do so one at a time and happily pay the price of bringing down the blob as needed. When the user selects an EmployeeDTO and&nbsp;"drills in to edit", you'll extract the Employee's ID and fetch the matching Employee from the database.</DIV><DIV>&nbsp;</DIV><DIV>Now you have the full Employee ... with the photo. But you were going to get the photo anyway, right? At least you're only getting one photo, not every photo of every employee in the list.</DIV><DIV>&nbsp;</DIV><DIV><strong>Important note</strong>: EmployeeDto is <strong><U>NOT</U></strong> an entity. EmployeeDto is just a read-only&nbsp;bag of Employee data.&nbsp; The query result is not in cache. If you query aqain with the same criteria you'll get a conceptually duplicate set of EmployeeDtos. </DIV><DIV>&nbsp;</DIV><DIV>You shouldn't edit&nbsp;one of these things&nbsp;- don't be fooled by the public setters. You've got no validation&nbsp;or other business logic.&nbsp;You can't save this data back to the database&nbsp;(as it is now ... we have tricks ... but that's a different post).</DIV><DIV>&nbsp;</DIV><DIV>The DTO has no navigation properties to any other entities. You can enrich the DTO with such properties if you like; it's not hard but it's plumbing you'll have to write. </DIV><DIV>&nbsp;</DIV><DIV>Oh ... don't forget to "update" your EmployeeDto after the user edits the corresponding Employee. Remember that the Employee and the EmployeeDto have no knowledge of each other.</DIV><DIV>&nbsp;</DIV><DIV>This is not what you signed up for when you chose DevForce. You're&nbsp;going back to managing your data by hand.&nbsp;&nbsp;If you're doing a lot of this kind of thing, <strong>stop</strong> ... and reflect ... because you're not using DevForce as it was intended to be used. You are developing in a different paradigm. Not a bad paradigm, just a different one.</DIV><DIV>&nbsp;</DIV><DIV>There is a way to get closer to the DevForce paradigm. It requires a little more setup. It's the View approach.</DIV><DIV>&nbsp;</DIV><DIV><strong><FONT size=4>The View Approach</FONT></strong></DIV><DIV>&nbsp;</DIV><DIV><strong>Question</strong>: is the blob field nullable.&nbsp;&nbsp; Please say "yes".&nbsp; Because, if it is nullable, you can define in your database&nbsp;an updatable view&nbsp;over the Employee Table ... a view&nbsp;that excludes the EmployeePhoto column. Then you can create another view consisting of just the EmployeeID and the EmployeePhoto. And then you create two entities AS IF there were two tables.</DIV><DIV>&nbsp;</DIV><DIV>Entity Framework (and, therefore, DevForce) will permit you to define ReadOnly entities for these views. You can define Insert, Update, and Delete methods in EF for the Employee entity. For EmployeePhoto you should define Update and Delete ... never Insert; the act of creating a new Employee will result in an EmployeePhoto.</DIV><DIV>&nbsp;</DIV><DIV>Consult Julie Lerman's book on Entity Framework for details on these aspects of Entity Framework. She'll tell you how to write the CUD methods that make view-backed entities modifiable.</DIV><DIV>&nbsp;</DIV><DIV>I'm not going to go further into the details of this approach. To be honest, I haven't checked on our support for View CUD methods in DevForce 2010 RC and we may have postponed that support until a future release. </DIV><DIV>&nbsp;</DIV><DIV>We will support it and, even if we don't have that support baked in right now, I have a workaround in my back pocket to tide you over.&nbsp; I'm sure you'll let me know if this is the way you want to go.</DIV><DIV>&nbsp;</DIV><span style="font-size:10px"><br /><br />Edited by WardBell - 22-Apr-2010 at 3:59pm</span>]]>
   </description>
   <pubDate>Mon, 19 Apr 2010 18:41:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6524#6524</guid>
  </item> 
  <item>
   <title>Lazy-Loaded BLOB Property : DevForce 10.0 looks absolutely...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6504#6504</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=746" rel="nofollow">kshaban</a><br /><strong>Subject:</strong> 1723<br /><strong>Posted:</strong> 18-Apr-2010 at 11:41pm<br /><br />DevForce 10.0 looks absolutely great.<DIV>&nbsp;</DIV><DIV>However, I am stumped...</DIV><DIV>&nbsp;</DIV><DIV>How do I setup lazy loading of large properties on a BO?</DIV><DIV>&nbsp;</DIV><DIV>Thanks in advance,</DIV><DIV>&nbsp;</DIV><DIV>Kavan</DIV>]]>
   </description>
   <pubDate>Sun, 18 Apr 2010 23:41:30 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1723&amp;PID=6504#6504</guid>
  </item> 
 </channel>
</rss>