<?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 : Key is already present in this dictionary error</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Key is already present in this dictionary error</description>
  <pubDate>Thu, 30 Apr 2026 08:34:48 -700</pubDate>
  <lastBuildDate>Wed, 03 Oct 2012 06:11:46 -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=3682</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>Key is already present in this dictionary error : Good point. I have changed that...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14709#14709</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> 3682<br /><strong>Posted:</strong> 03-Oct-2012 at 6:11am<br /><br />Good point. I have changed that now. <br><br>Can you change the Factory class to also find internal methods? I've set InternalsVisibleTo to my DomainServices project, but of course Factory&lt;&gt; only looks for Public | Static right now. I will add it as a task on the tracker.<br>]]>
   </description>
   <pubDate>Wed, 03 Oct 2012 06:11:46 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14709#14709</guid>
  </item> 
  <item>
   <title>Key is already present in this dictionary error :   Mark,That looks pretty good....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14706#14706</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> 3682<br /><strong>Posted:</strong> 03-Oct-2012 at 5:46am<br /><br />Mark,<div>That looks pretty good. The one thing I would change is to not pass the entire Customer entity to CreateAddress. That method doesn't need a whole customer, it only needs the id.</div><div>&nbsp;</div><div>public async Task&lt;CustomerAddress&gt; CreateAddress(int customerId)<br>        {<br>           &nbsp;&nbsp; var address = await _customerAddressFactory.CreateAsync();<br>&nbsp;&nbsp;&nbsp;address.CustomerId = customerId;<br>           &nbsp;&nbsp; return await TaskFns.FromResult(address);<br>        }</div>]]>
   </description>
   <pubDate>Wed, 03 Oct 2012 05:46:04 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14706#14706</guid>
  </item> 
  <item>
   <title>Key is already present in this dictionary error :   I just wrote a little service...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14702#14702</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> 3682<br /><strong>Posted:</strong> 02-Oct-2012 at 5:34pm<br /><br />&nbsp;I just wrote a little service today to do this, for my project. So far I've only done a fake store implementation. For a real implementation you would simply use a remote service method, and then on the server side execute your query to get the next id.<br><br><table width="99%"><tr><td class="BBquote"><br>&nbsp;&nbsp;&nbsp; public interface IKeyService&lt;T&gt; : IHideObjectMembers<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Task AllocateRange(int count);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Task&lt;T&gt; GetNext();<br>&nbsp;&nbsp;&nbsp; }<br></td></tr></table><br><br><table width="99%"><tr><td class="BBquote"><br>&nbsp;&nbsp;&nbsp; public class FakeStoreIntegerKeyService : IKeyService&lt;int&gt;<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private int _nextId;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private readonly Queue&lt;int&gt; _availableKeys;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public FakeStoreIntegerKeyService()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _nextId = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _availableKeys = new Queue&lt;int&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Implementation of IKeyService&lt;int&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Task AllocateRange(int count)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (var i = 0; i &lt; count; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _availableKeys.Enqueue(_nextId++);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TaskFns.FromResult(true);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Task&lt;int&gt; GetNext()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (_availableKeys.Count == 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AllocateRange(1);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TaskFns.FromResult(_availableKeys.Dequeue());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br>&nbsp;&nbsp;&nbsp; }<br></td></tr></table><br><br>I have multiple models so I just made an interface for this specific model so I'm not sharing keys between different models. You could bypass this step.<br><br><table width="99%"><tr><td class="BBquote"><br>&nbsp;&nbsp;&nbsp; public interface IDemoKeyService : IKeyService&lt;int&gt;<br>&nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp; public class DemoFakeKeyService : FakeStoreIntegerKeyService, IDemoKeyService<br>&nbsp;&nbsp;&nbsp; {<br><br>&nbsp;&nbsp;&nbsp; }<br></td></tr></table><br><br>I then subclassed Factory&lt;T&gt; to include my Key Service<br><br><table width="99%"><tr><td class="BBquote"><br>public class DemoFactory&lt;T&gt; : Factory&lt;T&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where T : Entity<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private readonly IDemoKeyService _keyService;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public DemoFactory(IEntityManagerProvider&lt;DemoEntities&gt; entityManagerProvider, IDemoKeyService keyService)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : base(entityManagerProvider)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _keyService = keyService;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override async System.Threading.Tasks.Task&lt;T&gt; CreateAsync(System.Threading.CancellationToken cancellationToken)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var entity = await base.CreateAsync(cancellationToken);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cancellationToken.ThrowIfCancellationRequested();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var key = await _keyService.GetNext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cancellationToken.ThrowIfCancellationRequested();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetKey(entity, key);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return await TaskFns.FromResult(entity);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void SetKey(T entity, int key)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var keyProperty = entity.EntityAspect.EntityMetadata.KeyProperties.FirstOrDefault();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entity.EntityAspect.SetValue(keyProperty, key);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br></td></tr></table><br><br>In my sample project I have a Customer and a CustomerAddress table. Previously I could do Customer.AddAddress() but I wasn't sure the cleanest way to implement that anymore. So I simply made a new Factory class to handle this:<br><br><table width="99%"><tr><td class="BBquote"><br>&nbsp;&nbsp;&nbsp; public class CustomerFactory : ICustomerFactory<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private readonly DemoFactory&lt;Customer&gt; _customerFactory;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private readonly DemoFactory&lt;CustomerAddress&gt; _customerAddressFactory; <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public CustomerFactory(IEntityManagerProvider&lt;DemoEntities&gt; entityManagerProvider, IDemoKeyService keyService)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _customerFactory = new DemoFactory&lt;Customer&gt;(entityManagerProvider, keyService);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _customerAddressFactory = new DemoFactory&lt;CustomerAddress&gt;(entityManagerProvider, keyService);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Implementation of ICustomerFactory<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Task&lt;Customer&gt; CreateCustomer()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _customerFactory.CreateAsync(CancellationToken.None);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public async Task&lt;CustomerAddress&gt; CreateAddress(int customerId)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var address = await _customerAddressFactory.CreateAsync();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; address.CustomerId = customerId;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return await TaskFns.FromResult(address);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br>&nbsp;&nbsp;&nbsp; }<br></td></tr></table><br><br>I then expose the ICustomerFactory on my UnitOfWork. I can then simply do:<br><br><table width="99%"><tr><td class="BBquote"><br>&nbsp;Address = await UnitOfWork.CustomerFactory.CreateAddress(Customer);<br></td></tr></table><br><br>If Marcel has a better way of doing this, I'm all ears. Hopefully this will give you enough to get started though.<br><br><br><br><span style="font-size:10px"><br /><br />Edited by smi-mark - 03-Oct-2012 at 6:08am</span>]]>
   </description>
   <pubDate>Tue, 02 Oct 2012 17:34:31 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14702#14702</guid>
  </item> 
  <item>
   <title>Key is already present in this dictionary error : I&amp;#039;m looking at replacing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14691#14691</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> 3682<br /><strong>Posted:</strong> 02-Oct-2012 at 8:57am<br /><br />I'm looking at replacing our db generated keys with such a key service.<br><br>I was planning on making an IKeyService interface, with a fakestore implementation that would just increment, and a real implementation that would call a remote service method to get the next, or next range of keys. <br><br>If you used the table based id generator from previous versions of devforce, it would do something similar. However it would only update the key on save, as far as I remember. <br>]]>
   </description>
   <pubDate>Tue, 02 Oct 2012 08:57:46 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14691#14691</guid>
  </item> 
  <item>
   <title>Key is already present in this dictionary error : If i used a Sequence(Sql Server...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14684#14684</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1213" rel="nofollow">jlozina</a><br /><strong>Subject:</strong> 3682<br /><strong>Posted:</strong> 02-Oct-2012 at 3:07am<br /><br />If i used a Sequence(Sql Server 2012) as a central key service&nbsp;like<DIV><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas><P></FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>CREATE</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>SEQUENCE</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>dbo</FONT></FONT></FONT><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas>.</FONT></FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>OrderSequence</P></FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas><P></FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>START</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>WITH</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> 1000</P><P></FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>INCREMENT</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>BY</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> 1 </FONT></FONT><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas>;</P><DIV><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><P>SELECT</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT color=#000000 size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>NEXT</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT color=#000000 size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>VALUE</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT color=#000000 size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>FOR</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT color=#000000 size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>dbo</FONT></FONT></FONT><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas>.</FONT></FONT></FONT><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas><FONT color=#008080 size=2 face=C&#111;nsolas>OrderSequence</FONT></FONT></FONT><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas><FONT color=#808080 size=2 face=C&#111;nsolas>;</P></FONT></FONT></FONT></FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas></FONT></FONT></DIV><DIV>how would I call it using&nbsp;code first? </DIV></DIV><DIV>&nbsp;</DIV><DIV>Are&nbsp;there any other ways to use a central key service if I want to continue using an int as a surogate key?</DIV>]]>
   </description>
   <pubDate>Tue, 02 Oct 2012 03:07:35 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14684#14684</guid>
  </item> 
  <item>
   <title>Key is already present in this dictionary error : You need a unique surrogate or...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14680#14680</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> 3682<br /><strong>Posted:</strong> 01-Oct-2012 at 1:03pm<br /><br />You need a unique surrogate or business key if you want to manage multiple units of work as demonstrated in TempHire and still use DB generated keys.<div><br></div><div>The issue with DB generated keys is that entities get a temporary key until they are saved. This violates the fundamental principle that says the identity of an entity should never change. The temporary Ids are only unique withing a single EntityManager/Unit of Work. They typically start at -100 then -101 and so on. If you create a second EntityManager/UoW it also starts at -100. That's the issue you are having here.&nbsp;</div><div><br></div><div>If you use DB generated keys, you'll be constantly figuring out how to&nbsp;reconcile&nbsp;things in the UI. You'll need something else in your entities that is unique and can be used as the key to identify the corresponding unit of work. You can't use the temporary Ids, because they are not guaranteed to be unique.&nbsp;</div><div><br></div><div>We generally advise against DB generated keys. They do not agree with the rich client computing paradigm where entities are created on the client. The Ids should be generated where the entity is created and once generated it shouldn't change, so the entity can always be uniquely identified. There are two ways to do this. Use a central key service or use Guids.</div>]]>
   </description>
   <pubDate>Mon, 01 Oct 2012 13:03:14 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14680#14680</guid>
  </item> 
  <item>
   <title>Key is already present in this dictionary error :  Hi  I am using an int as the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14675#14675</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1213" rel="nofollow">jlozina</a><br /><strong>Subject:</strong> 3682<br /><strong>Posted:</strong> 01-Oct-2012 at 7:01am<br /><br /><DIV></DIV><DIV>Hi</DIV><DIV>&nbsp;</DIV><DIV>I am using an int as the primary key and it is genrated by the database. When I create one record it works fine but when I try to create a second record with a unit of work I get the following error. This happens when I clear the unit of work or set it to null.</DIV><DIV>&nbsp;</DIV><DIV>System.ArgumentException was unhandled by user code<BR>&nbsp; HResult=-2147024809<BR>&nbsp; Message=Key is already present in this dictionary<BR>&nbsp; Source=Cocktail<BR>&nbsp; StackTrace:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at Cocktail.WeakRefDictionary`2.Add(TKey key, TValue value)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at Cocktail.ObjectManager`2.Add(TKey key, T obj)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at Services.Order.WizardUnitOfWorkManager.Services.IWizardUnitOfWorkManager&lt;Services.IWizardUnitOfWork&gt;.Add(Int32 , IWizardUnitOfWork )<BR></DIV><DIV>In my enity class the Id is set up this way</DIV><DIV><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>&#091;</FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>DataMember</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>&#093;</DIV><DIV><P>&#091;</FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>DatabaseGenerated</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>(</FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>DatabaseGeneratedOption</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>.Identity)&#093;</P><DIV>&#091;</FONT></FONT><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas><FONT color=#2b91af size=2 face=C&#111;nsolas>Required</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>&#093;</DIV><P></FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>public</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>int</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas> Id { </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>get</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>; </FONT></FONT><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas><FONT color=#0000ff size=2 face=C&#111;nsolas>set</FONT></FONT></FONT><FONT size=2 face=C&#111;nsolas><FONT size=2 face=C&#111;nsolas>; }</P></FONT></FONT></DIV><DIV>I noticed that the sample app&nbsp;uses a Guid for the primary key and DatabaseGeenratedOption is none. Is it possible to use the UnitOfWork with an int as the primary key?</DIV><DIV>&nbsp;</DIV><DIV>Regards,</DIV><DIV>Joe</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Mon, 01 Oct 2012 07:01:27 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3682&amp;PID=14675#14675</guid>
  </item> 
 </channel>
</rss>