<?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 : Soft deletes and LINQ</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Soft deletes and LINQ</description>
  <pubDate>Fri, 24 May 2013 15:49:31 -700</pubDate>
  <lastBuildDate>Wed, 12 Jan 2011 06:39:39 -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=2350</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>Soft deletes and LINQ : thanks Dennis, I figured out why...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9630#9630</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=764" rel="nofollow">mikedfox</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 12-Jan-2011 at 6:39am<br /><br />thanks Dennis, I figured out why Ward is suggesting that - the queryinterceptor filter doesn't get applied to navigation properties.<DIV>&nbsp;</DIV><DIV>So if Author has Books, and I use the queryinterceptor filter method, querying books will not return the soft deleted rows, but accessing the Author.Books collection will. </DIV><DIV>&nbsp;</DIV><DIV>I thought I remembered the old pre-ef DevForce giving you a way to add a filter clause to a relationship. Wish that was still there. Guess I'll go with a) above, but that is a lot of relationships to go update :(</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Wed, 12 Jan 2011 06:39:39 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9630#9630</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : For those who are interested,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9418#9418</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 15-Dec-2010 at 5:50pm<br /><br />For those who are interested, here is an alternative solution suggested by Ward Bell.<div><p ="Ms&#111;normal"><span style="color:#1F497D">I prefer either of thefollowing:<o:p></o:p></span></p><p ="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><ul><li><span style="mso-fareast-font-family:Calibri;color:#1F497D"><span style="mso-list:  Ignore">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><span style="color:#1F497D">Two properties: onefor all and one for active books</span></li><li><span style="mso-fareast-font-family:Calibri;color:#1F497D"><span style="mso-list:  Ignore">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><span style="color:#1F497D">A property thatreturns only active books; a method (“GetAllBooks()”) that returns everything.</span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></li></ul><!--if !supLists--></p><p ="Ms&#111;normal"><span style="color:#1F497D">#2 is cleanest but you can’tbind to a method … which is why I usually end up with #1.</span><span style="color:#1F497D"><o:p>&nbsp;</o:p></span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></p><p ="Ms&#111;normal"><span style="color:#1F497D">Think about what Author.Booksshould return in the usual case. &nbsp;Should it (a) return all books or (b)return active books.</span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></p><p ="Ms&#111;normal"><span style="color:#1F497D">DevForce by default generates a“Books” property for the (a) interpretation. &nbsp;Most people want the “Books”property to behave like (b). Therefore, I would:</span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></p><p ="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo2"><ol><li><span style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:  Symbol;color:#1F497D"><span style="mso-list:Ignore">·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><span style="color:#1F497D">Rename (in the EDM)the “Books” navigation property to “AllBooks” (or some such convention)</span></li><li><span style="font-family:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:  Symbol;color:#1F497D"><span style="mso-list:Ignore">·<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span><span style="color:#1F497D">Add a custom “Books”property to the Author partial class that returns only active books.</span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></li></ol><!--if !supLists--></p><p ="Ms&#111;normal"><span style="color:#1F497D">One possible implementation ofthat custom property is:</span>&nbsp;</p><p ="Ms&#111;normal" style="margin-left:.5in;:#F2F2F2"><span style="font-size:10.0pt;font-family:C&#111;nsolas">&nbsp;<span style="color:blue">public</span>&nbsp;<span style="color:blue">partial</span>&nbsp;<span style="color:blue">class</span>&nbsp;<span style="color:green">// extends the generated Author class</span><br>&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:gray">///</span><span style="color:green">&nbsp;</span><span style="color:gray">&lt;summary&gt;</span><span style="color:green">Gets&nbsp;the Author’s active Books&nbsp;(books&nbsp;thatare not deleted).</span><span style="color:gray">&lt;/summary&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#091;<span style="color:#2B91AF">Bindable</span>(<span style="color:blue">false</span>)&#093;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#091;<span style="color:#2B91AF">Display</span>(Name&nbsp;=&nbsp;<span style="color:#A31515">"Books"</span>,&nbsp;AutoGenerateField&nbsp;=&nbsp;<span style="color:blue">false</span>)&#093;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">public</span>&nbsp;<span style="color:#2B91AF">RelatedEntityList</span>&lt;<span style="color:#2B91AF">Book</span>&gt;&nbsp;Books<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">get</span>&nbsp;{&nbsp;<span style="color:blue">return</span>&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2B91AF">RelatedEntityList</span>&lt;<span style="color:#2B91AF">Book</span>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">this</span>.Books.Where(b=&gt;b.Active == <span style="color:blue">true</span>),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2B91AF">PropertyMetadata</span>.Books.GetEntityReference(<span style="color:blue">this</span>)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;}<o:p></o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p><p ="Ms&#111;normal"><span style="color:#1F497D">It is no accident that thislooks very similar to the code that DevForce generated for <b>Author.AllBooks</b>.</span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></p><p ="Ms&#111;normal"><span style="color:#1F497D">It is not the only possibleimplementation. </span><span style="font-size:10.0pt;font-family:C&#111;nsolas;  color:#2B91AF">RelatedEntityList</span><span style="font-size:10.0pt;  font-family:C&#111;nsolas">&lt;<span style="color:#2B91AF">T</span>&gt;&nbsp;</span><span style="color:#1F497D">is a DevForce internal class … one that, in general, youshould not create yourself. The advantage is that this is a “live” list; if youtoggle a Book between active and deleted, this list updates automatically(adding or removing a Book automatically).</span><span ="Apple-style-span" style="color: rgb31, 73, 125; ">&nbsp;</span></p><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;mso-fareast-font-family:  Calibri;mso-fareast-theme-font:minor-latin;color:#1F497D;mso-ansi-:  EN-US;mso-fareast-:EN-US;mso-bidi-:AR-SA">Please remember thatsub-queries and INCLUDEs must be composed in terms of the <span style=":yellow;mso-highlight:yellow">AllBooks</span> property.&nbsp;Neither EF nor DevForce will recognize the Books property.</span></b></div>]]>
   </description>
   <pubDate>Wed, 15 Dec 2010 17:50:17 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9418#9418</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : Great. Thank you for sharing your...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9331#9331</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 08-Dec-2010 at 12:56pm<br /><br />Great. Thank you for sharing your solution guys.]]>
   </description>
   <pubDate>Wed, 08 Dec 2010 12:56:14 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9331#9331</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : Yes, you&amp;#039;ve got it. Using...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9328#9328</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=449" rel="nofollow">smi-mark</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 07-Dec-2010 at 3:55pm<br /><br />Yes, you've got it. Using the EntityServerQueryInterceptor, you can force it to always add a Where IsDeleted == false, so no matter what query you execute, it will only return entities that satisfy this condition.]]>
   </description>
   <pubDate>Tue, 07 Dec 2010 15:55:14 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9328#9328</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : I found an answer - EntityServerQueryInterceptor...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9326#9326</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=764" rel="nofollow">mikedfox</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 07-Dec-2010 at 7:59am<br /><br />I found an answer - <PRE style="FONT-FAMILY: c&#111;nsolas"><SPAN style="COLOR: #2b91af">EntityServerQueryInterceptor</SPAN><BR></PRE>]]>
   </description>
   <pubDate>Tue, 07 Dec 2010 07:59:27 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9326#9326</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : I don&amp;#039;t have control over...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9319#9319</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=764" rel="nofollow">mikedfox</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 06-Dec-2010 at 1:18pm<br /><br />I don't have control over the data model.]]>
   </description>
   <pubDate>Mon, 06 Dec 2010 13:18:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9319#9319</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : After reading this article:htt...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9318#9318</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 06-Dec-2010 at 12:47pm<br /><br />After reading this article:<div><br></div><div><a href="http://www.udidahan.com/2009/09/01/d&#111;nt-delete-just-d&#111;nt/" target="_blank">http://www.udidahan.com/2009/09/01/dont-delete-just-dont/</a></div><div><br></div><div>I think it makes more sense if you add another state to your Book object that marks it as a "mistake" and you can do a count query that excludes for this "mistake" state.</div>]]>
   </description>
   <pubDate>Mon, 06 Dec 2010 12:47:02 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9318#9318</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : Hi mikedfox;I did a google search...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9317#9317</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=912" rel="nofollow">DenisK</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 06-Dec-2010 at 12:36pm<br /><br />Hi mikedfox;<div><br></div><div>I did a google search on Soft Delete. I would say the top 3 results are worth reading depending on your application's requirement.&nbsp;</div><div><br></div><div>But I would say read this site first since it explores the reasons why we do soft deletes. It also attempts to provide a more elegant solution for each reason.</div><div><br></div><div><a href="http://richarddingwall.name/2009/11/20/the-trouble-with-soft-delete/" target="_blank">http://richarddingwall.name/2009/11/20/the-trouble-with-soft-delete/</a><br><div><br></div><div><br></div></div>]]>
   </description>
   <pubDate>Mon, 06 Dec 2010 12:36:39 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9317#9317</guid>
  </item> 
  <item>
   <title>Soft deletes and LINQ : This isn&amp;#039;t a problem specific...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9314#9314</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=764" rel="nofollow">mikedfox</a><br /><strong>Subject:</strong> 2350<br /><strong>Posted:</strong> 06-Dec-2010 at 11:04am<br /><br />This isn't a problem specific to DevForce, but I'm hoping DevForce provides a better answer than EF.<DIV>&nbsp;</DIV><DIV>I have a database where we are doing "soft deletes". So instead of a row being deleted, and IsDeleted flag is set to true. That way foreign key lookups still work, reporting on historical data still works, etc.</DIV><DIV>&nbsp;</DIV><DIV>The problem comes when I try to look up related data, especially binding.</DIV><DIV>&nbsp;</DIV><DIV>For example, let's say I have a book table and an author table. If hava reference to an author, I can bind to BookList.Count and see how many books are out there. Butr if one of the entries was a mistake, and has been marked as IsDeleted, how do I get the count straight? I know I can do another linq query, but can anyone figure out a better way? Would it be better to add properties on each partial class (ie UndeletedBooks on Author? Is there something EnttyListManager could add?</DIV><DIV>&nbsp;</DIV><DIV>I know how to btrute force this, I'm jsut hoping there's a more elegant solution.</DIV>]]>
   </description>
   <pubDate>Mon, 06 Dec 2010 11:04:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2350&amp;PID=9314#9314</guid>
  </item> 
 </channel>
</rss>