protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
First I think you should remove "throw new UnintentionalCodeFirstException();" this statement because when it's executed to this statement,error will be thrown out。
And then
QuantumInformation
The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?)
Please make sure that you've imported the EF dll and refer the namespace。In fact I strongly you using NuGet——this is a very nice tool that helps you to get EF dll and refer it easily and automatically。
QuantumInfor...
Member
199 Points
228 Posts
DB context code gen item generates incorrect code
Mar 13, 2012 01:53 PM|LINK
Hi :) I'm working with entity
I've asked VS to generate a DB context code gen item but get errors:
<div class="comment-right-col"> <div>is there somewhere I need to go to to get upto date templates?
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
Error 1 The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?)
any ideas?
</div> </div>Bimalvv
Contributor
2356 Points
478 Posts
Re: DB context code gen item generates incorrect code
Mar 13, 2012 06:34 PM|LINK
Which version of EF are you using.
Bimal
QuantumInfor...
Member
199 Points
228 Posts
Re: DB context code gen item generates incorrect code
Mar 14, 2012 09:38 AM|LINK
I have this on my pc:
C:\Program Files (x86)\Microsoft ADO.NET Entity Framework 4.1 RC
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: DB context code gen item generates incorrect code
Mar 15, 2012 01:54 AM|LINK
First I think you should remove "throw new UnintentionalCodeFirstException();" this statement because when it's executed to this statement,error will be thrown out。
And then
Please make sure that you've imported the EF dll and refer the namespace。In fact I strongly you using NuGet——this is a very nice tool that helps you to get EF dll and refer it easily and automatically。
Now you can see this and follow the steps:http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
QuantumInfor...
Member
199 Points
228 Posts
Re: DB context code gen item generates incorrect code
Mar 15, 2012 06:03 PM|LINK
cheers decker :)
I installed ef 4.1 using new the package manager before, and I see in the references folder
system.data.entity
And I have the errors still.
why should I delete that code that throws the error since it was generated by entity?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: DB context code gen item generates incorrect code
Mar 16, 2012 01:04 AM|LINK
Your throw new Exception……is fully automatically generated by EF?Sorry if so,plz keep it。(PS:I don't remember I have ever seen it before……)Haha……
This is the namespace,and is there an EntityFramework.dll there?
QuantumInfor...
Member
199 Points
228 Posts
Re: DB context code gen item generates incorrect code
Mar 19, 2012 10:09 AM|LINK
yes,
Assembly System.Data.Entity
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Entity.dll
however in the NuGet I see I have entity v4.1 ?