DB context code gen item generates incorrect codehttp://forums.asp.net/t/1779842.aspx/1?DB+context+code+gen+item+generates+incorrect+codeMon, 19 Mar 2012 10:09:35 -040017798424877791http://forums.asp.net/p/1779842/4877791.aspx/1?DB+context+code+gen+item+generates+incorrect+codeDB context code gen item generates incorrect code <p>Hi :) I'm working with entity</p> <p>I've asked VS to generate a DB context code gen item but get errors:</p> &lt;div class=&quot;comment-right-col&quot;&gt; &lt;div&gt; <p>is there somewhere I need to go to to get upto date templates?</p> <p>&nbsp; protected override void OnModelCreating(DbModelBuilder modelBuilder)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new UnintentionalCodeFirstException();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>Error&nbsp;&nbsp; &nbsp;1<strong><span style="text-decoration:underline">&nbsp;&nbsp; &nbsp;The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?)&nbsp;&nbsp;</span></strong></p> <p></p> <p>any ideas?<span style="text-decoration:underline"></span><strong><span style="text-decoration:underline"><br> </span></strong></p> &lt;/div&gt; &lt;/div&gt; 2012-03-13T13:53:40-04:004878229http://forums.asp.net/p/1779842/4878229.aspx/1?Re+DB+context+code+gen+item+generates+incorrect+codeRe: DB context code gen item generates incorrect code <p>Which version of EF are you using.</p> 2012-03-13T18:34:27-04:004879375http://forums.asp.net/p/1779842/4879375.aspx/1?Re+DB+context+code+gen+item+generates+incorrect+codeRe: DB context code gen item generates incorrect code <p>I have this on my pc:</p> <p></p> <p>C:\Program Files (x86)\Microsoft ADO.NET Entity Framework 4.1 RC</p> 2012-03-14T09:38:40-04:004880809http://forums.asp.net/p/1779842/4880809.aspx/1?Re+DB+context+code+gen+item+generates+incorrect+codeRe: DB context code gen item generates incorrect code <p></p> <blockquote><span class="icon-blockquote"></span> <h4>QuantumInformation</h4> protected override void OnModelCreating(DbModelBuilder modelBuilder)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new UnintentionalCodeFirstException();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</blockquote> <p></p> <p>First I think you should remove &quot;throw new UnintentionalCodeFirstException();&quot; this statement because when it's executed to this statementerror will be thrown out</p> <p>And then</p> <p>&nbsp;</p> <blockquote><span class="icon-blockquote"></span> <h4>QuantumInformation</h4> The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?)&nbsp;&nbsp;</blockquote> <p></p> <p>Please make sure that you've imported the EF dll and refer the namespaceIn fact I strongly you using NuGetthis is a very nice tool that helps you to get EF dll and refer it easily and automatically</p> <p>Now you can see this and follow the steps<a href="http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx">http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx</a></p> 2012-03-15T01:54:14-04:004882335http://forums.asp.net/p/1779842/4882335.aspx/1?Re+DB+context+code+gen+item+generates+incorrect+codeRe: DB context code gen item generates incorrect code <p>cheers decker :)</p> <p></p> <p>I installed ef 4.1 using new the package manager before, and I see in the references folder</p> <p>system.data.entity</p> <p>&nbsp;And I have the errors still.</p> <p></p> <p>why should I delete that code that throws the error since it was generated by entity?</p> 2012-03-15T18:03:14-04:004882699http://forums.asp.net/p/1779842/4882699.aspx/1?Re+DB+context+code+gen+item+generates+incorrect+codeRe: DB context code gen item generates incorrect code <p></p> <blockquote><span class="icon-blockquote"></span> <h4>QuantumInformation</h4> why should I delete that code that throws the error since it was generated by entity?</blockquote> <p></p> <p>Your throw new Exceptionis fully automatically generated by EFSorry if soplz keep itPSI don't remember I have ever seen it beforeHaha</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>QuantumInformation</h4> system.data.entity</blockquote> <p></p> <p>This is the namespaceand is there an EntityFramework.dll there</p> 2012-03-16T01:04:47-04:004887106http://forums.asp.net/p/1779842/4887106.aspx/1?Re+DB+context+code+gen+item+generates+incorrect+codeRe: DB context code gen item generates incorrect code <p>yes,</p> <p></p> <p>Assembly System.Data.Entity<br> &nbsp;&nbsp;&nbsp; C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Entity.dll</p> <p></p> <p>however in the NuGet I see I have entity v4.1&nbsp;&nbsp; ?</p> 2012-03-19T10:09:35-04:00