<?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 : Saving an entity using ApplicationRepository</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Saving an entity using ApplicationRepository</description>
  <pubDate>Sat, 11 Apr 2026 05:38:30 -700</pubDate>
  <lastBuildDate>Thu, 12 Jul 2012 01:05:50 -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=3517</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>Saving an entity using ApplicationRepository : Sorry about the delayed response....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3517&amp;PID=14002#14002</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3517<br /><strong>Posted:</strong> 12-Jul-2012 at 1:05am<br /><br />Sorry about the delayed response. I just got back from vacation. Your CreateDashBoard method is not a create method if you have to pass the entity as a parameter. That would mean you have to create the entity outside of the method, which kind of defeats the purpose of the method, don't you think? Also, if the creation isn't asynchronous, just make the method synchronous.<div><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; "><span style="color: blue; "><br ="Apple-interchange-newline">public</span>&nbsp;<span style="color: rgb43, 145, 175; ">DBOARD</span>&nbsp;CreateDashBoard()</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp;&nbsp; {</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp; &nbsp; &nbsp; &nbsp;var dashboard = new DBOARD();</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp; &nbsp; &nbsp; &nbsp;// Optional initialization of the newly created entity.</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; entityManagerProvider.Manager.AddEntity(dashboard);</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp;</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<span style="color: blue; ">return</span>&nbsp;<font color="#2b91af">dashboard;</font></p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp;&nbsp; }</p></div><div><br></div><div>As for the save method. If you return AlwaysCompletedOperationResult, the caller won't have any idea when the save is actually completed and whether it was successful or not. Also, if you don't override the default SaveOptions, don't bother with it. The save method should look like this.</div><div><br></div><div><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; "><span style="color: blue; ">public</span>&nbsp;<span style="color: rgb43, 145, 175; ">OperationResult&lt;SaveResult&gt;</span>&nbsp;SaveAsync(<span style="color: rgb43, 145, 175; ">Action</span>&lt;<span style="color: rgb43, 145, 175; ">SaveResult</span>&gt; onSuccess = null, Action&lt;Exception&gt; onFail = null)</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp; {</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return entityManagerProvider.Manager</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; "><span style=": white; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.SaveChangesAsync(op&nbsp;=&gt;&nbsp;op.OnComplete(onSuccess,&nbsp;onFail))</span></p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; "><span style=": white; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.AsOperationResult()</span>;</p><p style="font-family: C&#111;nsolas; font-size: 13px; line-height: 18px; text-align: left; : rgb251, 251, 253; margin: 0px; ">&nbsp; &nbsp; &nbsp;}</p></div><div><br></div><div>Finally, to relate entities, you simple add them to the respective navigation property/collection before you save, or set the applicable foreign key property to the correct key (not applicable for many-to-many).</div><div><br></div><div>For example as seen in TempHire, the following StaffingResource method relates a newly created address entity to the StaffingResource by simply adding it to the Addresses collection.</div><div><br></div><div><pre style="font-family: C&#111;nsolas; font-size: 13px; : white; -: initial initial; -repeat: initial initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">public</span>&nbsp;<span style="color:#2b91af;">Address</span>&nbsp;AddAddress(<span style="color:#2b91af;">AddressType</span>&nbsp;type)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af;">Address</span>&nbsp;address&nbsp;=&nbsp;<span style="color:#2b91af;">Address</span>.Create(type);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Addresses.Add(address); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">return</span>&nbsp;address;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</pre></div><div><div><br></div></div>]]>
   </description>
   <pubDate>Thu, 12 Jul 2012 01:05:50 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3517&amp;PID=14002#14002</guid>
  </item> 
  <item>
   <title>Saving an entity using ApplicationRepository : Hello,I&amp;#039;m using an applicationrepository...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3517&amp;PID=13950#13950</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1136" rel="nofollow">pponzano</a><br /><strong>Subject:</strong> 3517<br /><strong>Posted:</strong> 05-Jul-2012 at 6:49am<br /><br />Hello,<br>I'm using an applicationrepository (and IApplicationRepository) to have access to DB, I was wondering if it's correct to have<br><br><div style="font-family: C&#111;nsolas; font-size: 10pt; color: black; : white;"><p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: #2b91af;">OperationResult</span> CreateDashBoard(<span style="color: #2b91af;">DBOARD</span> dashboard, <span style="color: #2b91af;">Action</span>&lt;<span style="color: #2b91af;">IEnumerable</span>&gt; onSuccess = <span style="color: blue;">null</span>, <span style="color: #2b91af;">Action</span>&lt;<span style="color: #2b91af;">Exception</span>&gt; onFail = <span style="color: blue;">null</span>)</p><p style="margin: 0px;">&nbsp;&nbsp; {</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; entityManagerProvider.Manager.AddEntity(dashboard);</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">AlwaysCompletedOperationResult</span>.Instance;</p><p style="margin: 0px;">&nbsp;&nbsp; }</p></div><br><br>and (to perform the save)<br><br><div style="font-family: C&#111;nsolas; font-size: 10pt; color: black; : white;"><p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: #2b91af;">OperationResult</span> SaveAsync(<span style="color: #2b91af;">Action</span>&lt;<span style="color: #2b91af;">EntitySaveOperation</span>&gt; onSuccess )</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp; {</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">SaveOptions</span> saveOptions = <span style="color: blue;">new</span> <span style="color: #2b91af;">SaveOptions</span>();</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; entityManagerProvider.Manager.SaveChangesAsync(saveOptions,onSuccess);</p><p style="margin: 0px;">&nbsp;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">AlwaysCompletedOperationResult</span>.Instance;</p><p style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp; }</p></div><br>My Entity DBOARD also has a relation to LAYOUT... in my view I've a dropdown form where to choose the layout.....since DBOARD &lt;-&gt; LAYOUT is a MXN relation (I can have more dashboard with the same layout) how do I define this realation when saving?<br>Thanks<br>]]>
   </description>
   <pubDate>Thu, 05 Jul 2012 06:49:49 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3517&amp;PID=13950#13950</guid>
  </item> 
 </channel>
</rss>