<?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 : DF &amp; EF 4.3 Migrations many-to-many seed data</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : DF &amp; EF 4.3 Migrations many-to-many seed data</description>
  <pubDate>Wed, 13 May 2026 09:44:15 -700</pubDate>
  <lastBuildDate>Tue, 06 Mar 2012 18:03:10 -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=3318</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>DF &amp; EF 4.3 Migrations many-to-many seed data : Hi esaulsberry;There are a couple...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3318&amp;PID=12903#12903</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> 3318<br /><strong>Posted:</strong> 06-Mar-2012 at 6:03pm<br /><br />Hi esaulsberry;<div><br></div><div>There are a couple of things that you need to change here.</div><div><br></div><div>1. RelatedEntityList is not supposed to have a setter. See <a href="http://drc.ideablade.com/xwiki/bin/view/&#068;ocumentati&#111;n/code-first-entity-classes#HPersistednavigati&#111;nproperties" target="_blank">here </a>for further discussion.</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode"></div><div>public RelatedEntityList&lt;Publication&gt; Publications { get { return null; } }</div><div>public RelatedEntityList&lt;Subscriber&gt; Subscribers { get { return null; } }</div><div></pre></td></tr></table></div><div><br></div><div>2. Because RelatedEntityList is not settable, you need to change your seed method as follows,</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode"></div><div><div>&nbsp; &nbsp; &nbsp; var pub = new Publication {.........};</div><div>&nbsp; &nbsp; &nbsp; var sub = new Subscriber {..........};</div><div>&nbsp; &nbsp; &nbsp; pub.Subscribers.Add(sub);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; context.Publications.AddOrUpdate(pub);</div></div><div></pre></td></tr></table></div>]]>
   </description>
   <pubDate>Tue, 06 Mar 2012 18:03:10 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3318&amp;PID=12903#12903</guid>
  </item> 
  <item>
   <title>DF &amp; EF 4.3 Migrations many-to-many seed data :   Is it possible to populate...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3318&amp;PID=12889#12889</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1307" rel="nofollow">esaulsberry</a><br /><strong>Subject:</strong> 3318<br /><strong>Posted:</strong> 05-Mar-2012 at 9:22am<br /><br /><p>Is it possible to populate the association table for a many-to-many relationship in&nbsp;EF 4.3 Migration's Configuration.Seed method using DF?</p><p>I have a couple of classes with a many to many relationship defined as:</p><div><span style="color: blue;"><pre style=": white; color: black; font-family: Bitstream Vera Sans Mono;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">class</span>&nbsp;<span style="color: rgb43, 145, 175;">Publication</span>&nbsp;:&nbsp;<span style="color: rgb43, 145, 175;">EntityBase</span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">int</span>&nbsp;PublicationId&nbsp;{&nbsp;<span style="color: blue;">get</span>;&nbsp;<span style="color: blue;">set</span>;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">string</span>&nbsp;Name&nbsp;{&nbsp;<span style="color: blue;">get</span>;&nbsp;<span style="color: blue;">set</span>;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: rgb43, 145, 175;">RelatedEntityList</span>&lt;<span style="color: rgb43, 145, 175;">Subscriber</span>&gt;&nbsp;Subscribers&nbsp;{&nbsp;<span style="color: blue;">get</span>;&nbsp;<span style="color: blue;">set</span>;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;}</pre><p></span>&nbsp;</p><pre style=": white; color: black; font-family: Bitstream Vera Sans Mono;"><p><span style="color: blue;">public </span><span style="color: blue;">class </span><span style="color: rgb43, 145, 175;">Subscriber</span> : <span style="color: rgb43, 145, 175;">EntityBase</span>    {        <span style="color: blue;">public</span><span style="color: blue;">int</span> SubscriberId { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }        <span style="color: blue;">public</span><span style="color: blue;">string</span> Name { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }         <span style="color: blue;">public</span><span style="color: rgb43, 145, 175;">RelatedEntityList</span>&lt;<span style="color: rgb43, 145, 175;">Publication</span>&gt; Publications { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }    }</p><p>The context includes:</p><pre style=": white; color: black; font-family: Bitstream Vera Sans Mono;">        <span style="color: blue;">public</span> <span style="color: rgb43, 145, 175;">DbSet</span>&lt;<span style="color: rgb43, 145, 175;">Publication</span>&gt; Publications { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }         <span style="color: blue;">public</span> <span style="color: rgb43, 145, 175;">DbSet</span>&lt;<span style="color: rgb43, 145, 175;">Subscriber</span>&gt; Subscribers { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</pre><p>This generated the tables I expect: Subscribers, Publications, and SubscriberPublications.  In the configuration seed method, I can add some sample data:</p><pre style=": white; color: black; font-family: Bitstream Vera Sans Mono;"><p>            context.Publications.AddOrUpdate(<span style="color: blue;">new</span><span style="color: rgb43, 145, 175;">Publication</span> { PublicationId = 1, Name = <span style="color: rgb163, 21, 21;">"pub 1"</span> });            context.Publications.AddOrUpdate(<span style="color: blue;">new</span><span style="color: rgb43, 145, 175;">Publication</span> { PublicationId = 2, Name = <span style="color: rgb163, 21, 21;">"pub 2"</span> });             context.Subscribers.AddOrUpdate(<span style="color: blue;">new</span><span style="color: rgb43, 145, 175;">Subscriber</span> { SubscriberId = 1, Name = <span style="color: rgb163, 21, 21;">"Dude 1"</span> });            context.Subscribers.AddOrUpdate(<span style="color: blue;">new</span><span style="color: rgb43, 145, 175;">Subscriber</span> { SubscriberId = 2, Name = <span style="color: rgb163, 21, 21;">"Dude 2"</span> });</p><p>What I don't seem to be able to do is</p><p>            context.Publications.AddOrUpdate(<span style="color: blue;">new</span><span style="color: rgb43, 145, 175;">Publication</span> {PublicationId = 1, Name = <span style="color: rgb163, 21, 21;">"pub 1", Subscribers.Add(somedude)</span> });</p><div><p>and so my assocation table SubscriberPublications is empty.  </p></div><p>The EF forum recommended way with plain EF,</p><div>context.Publications.AddOrUpdate(</div><div>new Publication { </div><div>	PublicationId = 1, </div><div>	Name = "pub 1", </div><div>	Subscribers = new List&lt;Subscriber&gt;() </div><div>		{ new Subscriber { SubscriberId = 1, Name = "Dude 1" }, </div><div>		new Subscriber { SubscriberId = 2, Name = "Dude 2" } } });</div><div>&nbsp;</div><div>modified for my classes:</div><div><pre style=": white; color: black; font-family: Bitstream Vera Sans Mono;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.Publications.AddOrUpdate(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: rgb43, 145, 175;">Publication</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PublicationId&nbsp;=&nbsp;1,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;=&nbsp;<span style="color: rgb163, 21, 21;">"pub&nbsp;1"</span>,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subscribers&nbsp;=&nbsp;<span style="color: blue;">new</span>&nbsp;IdeaBlade.EntityModel.<span style="color: rgb43, 145, 175;">RelatedEntityList</span>&lt;<span style="color: rgb43, 145, 175;">Subscriber</span>&gt;()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">new</span>&nbsp;<span style="color: rgb43, 145, 175;">Subscriber</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SubscriberId=1,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name=<span style="color: rgb163, 21, 21;">"Dude&nbsp;1"</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); </pre><pre style=": white; color: black; font-family: Bitstream Vera Sans Mono;">&nbsp;</pre></div><div>results in this exception:</div><div><pre style=": white; color: black; font-family: C&#111;nsolas;">Running&nbsp;Seed&nbsp;method.System.NotSupportedException:&nbsp;Sets&nbsp;on&nbsp;List&nbsp;Navigation&nbsp;properties&nbsp;are&nbsp;not&nbsp;supported&nbsp;&nbsp;&nbsp;at&nbsp;IdeaBlade.EntityModel.NavigationListEntityProperty`2.SetValue(Object&nbsp;instance,&nbsp;Object&nbsp;value)&nbsp;&nbsp;&nbsp;at&nbsp;IdeaBlade.Aop.ProvideEntityAspect.PropertySetInterceptor(LocationInterceptionArgs&nbsp;args)&nbsp;&nbsp;&nbsp;at&nbsp;DbModel.Models.Publication.set_Subscribers(RelatedEntityList`1&nbsp;value)&nbsp;in&nbsp;:line&nbsp;0&nbsp;&nbsp;&nbsp;at&nbsp;DbModel.Migrations.Configuration.Seed(DbModelContext&nbsp;context)&nbsp;in&nbsp;H:\Projects\2&nbsp;-&nbsp;Research&nbsp;Projects\EFCF\SilverlightApplication2\DbModel\Migrations\Configuration.cs:line&nbsp;42&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.DbMigrationsConfiguration`1.OnSeed(DbContext&nbsp;context)&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.DbMigrator.SeedDatabase()&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1&nbsp;pendingMigrations,&nbsp;String&nbsp;targetMigrationId,&nbsp;String&nbsp;lastMigrationId)&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1&nbsp;pendingMigrations,&nbsp;String&nbsp;targetMigrationId,&nbsp;String&nbsp;lastMigrationId)&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.DbMigrator.Update(String&nbsp;targetMigration)&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String&nbsp;targetMigration)&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()&nbsp;&nbsp;&nbsp;at&nbsp;System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()<span style="color: red;">Sets&nbsp;on&nbsp;List&nbsp;Navigation&nbsp;properties&nbsp;are&nbsp;not&nbsp;supported</span></pre></div><p>Is there a way to populate the assocation table from the seed method with DF?</p><p>Thanks.</p></pre></pre></div>]]>
   </description>
   <pubDate>Mon, 05 Mar 2012 09:22:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3318&amp;PID=12889#12889</guid>
  </item> 
 </channel>
</rss>