<?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 : Add and Save</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Add and Save</description>
  <pubDate>Sat, 11 Apr 2026 07:07:33 -700</pubDate>
  <lastBuildDate>Wed, 21 Jul 2010 15:32:53 -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=1972</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>Add and Save : Not sure what the issue is, but...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1972&amp;PID=7728#7728</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1972<br /><strong>Posted:</strong> 21-Jul-2010 at 3:32pm<br /><br />Not sure what the issue is, but your code above doesn't show where your 'person' value comes from.<br /><br />In NorthwindIB, Order and Customer are related 0-1. The following code works fine, and reports 1 entity saved. (I've removed the statements that produce the output, as they're specific to my app.)<br /><br /><table width="99%"><tr><td><pre class="BBcode"><br />&nbsp;&nbsp;&nbsp;&nbsp;public void Test1to1AddAndSave() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var customersQuery = _em1.Customers<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Where(c =&gt; c.ContactTitle == "Sales Representative")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .OrderBy(c =&gt; c.CompanyName);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_em1.ExecuteQueryAsync&lt;Customer&gt;(customersQuery, GotCustomers, null);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;private void GotCustomers(EntityQueryOperation&lt;Customer&gt; args) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Order newOrder = _em1.CreateEntity&lt;Order&gt;();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newOrder.OrderDate = DateTime.Today;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newOrder.Customer = args.Results.FirstOrDefault();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_em1.SaveChangesAsync(op =&gt; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (op.HasError) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// output error message<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// output count of entities saved // reports "1"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, null);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /></pre></td></tr></table><br />]]>
   </description>
   <pubDate>Wed, 21 Jul 2010 15:32:53 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1972&amp;PID=7728#7728</guid>
  </item> 
  <item>
   <title>Add and Save : SilverlightI have an object &amp;#039;Person&amp;#039;...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1972&amp;PID=7673#7673</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=809" rel="nofollow">adamh</a><br /><strong>Subject:</strong> 1972<br /><strong>Posted:</strong> 17-Jul-2010 at 11:52pm<br /><br />Silverlight<br><br>I have an object 'Person' that has a 0 or 1 relationship with an object 'Lunch'&nbsp; (i.e. it may have 1 or no lunch)<br>Both 'Person' and 'Lunch' have auto generated 'unique identifier'<br><br>I want to either.<br>Add a 'Lunch' to a 'Person' if they don't have one or modify the 'Lunch' if they do.<br><br>I am OK with modifying .. I just modify and call 'SaveChangesAsync'<br><br>But if I have a Person that does not have a 'Lunch' it appears as 'detached'<br><br>How do I Add and Save a 'Lunch'.<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Lunch lunch = em.CreateEntity&lt;Lunch&gt;();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lunch.Timestamp = DateTime.Now;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lunch.Name = "yummy";<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lunch.Person= person;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lunch.EntityAspect.AddToManager();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; em.SaveChangesAsync(Done, null);<br><br>I get a complaint about the foreign key.<strike><br><br></strike>System.Data.UpdateException: Entities in 'LogicOnEntities.Lunch' participate in the 'FK_PersonLunch' relationship. 0 related 'Person' were found. 1 'Person' is expected.<br><br>The other way I could do it is to work with the 'detached'&nbsp; Lunch .. but how do I do theta and Save it?<strike><br></strike><br>As well as a solution I would be intereste dto know where in the documentation this is cleary explained??<br><br>Thanks<strike><br><br><br><br></strike><br>]]>
   </description>
   <pubDate>Sat, 17 Jul 2010 23:52:39 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1972&amp;PID=7673#7673</guid>
  </item> 
 </channel>
</rss>