Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, February 7, 2009 4:36 PM
Hi Fourm.
Hi have a problem whiel I'm trying to access to an entity object within a ViewPage:
The problem si that when I import Syste.Data.Entity:
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.Entity" %>
I get this error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Source Error:
Line 5: <%@ Import Namespace = "UmlModels.Site.EntityFramework" %>
Line 6: <%@ Import Namespace = "System.Data" %>
Line 7: <%@ Import Namespace = "System.Data.Entity" %>
Line 8:
Line 9: <html xmlns="http://www.w3.org/1999/xhtml" >
I have manualy added System.Data.Entity reference to the project where is th asp.net mvc and I dont get any error when I import System.Data.Entity and use the entity in the Controller.
What I am skipping?
Thanks in advance.
All replies (17)
Monday, February 23, 2009 10:32 PM ✅Answered
I had the same problem.
Searching in Google I found the solution in: http://www.jfarrell.net/2008/10/tip-1-understanding-cryptic-mvc-errors.html
We need to add this line in our Web.Config:
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
This worked for me!
Tuesday, February 23, 2010 11:49 PM ✅Answered
add <%@ Assembly Name="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>
Thursday, July 29, 2010 9:46 AM ✅Answered
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
for Asp.net 4
Saturday, August 14, 2010 9:42 PM ✅Answered
To cheat - you can do the following:
Rightclick on the project name and add new item. Select ADO.NET Entity Data Model. It will open Entity Data Model Wizard. Select "Empty Model" and click Finish.
Now you can delete the generated file (Model.edmx), but what isn't done when you add Ssytem.Data.Entity manually - is now done.
I know it's a kluge... but it works!
Saturday, February 7, 2009 4:52 PM
why don't you add them as following in code behind
using System.Data;
using System.Data.Entity;
Sunday, February 8, 2009 5:15 AM
I did, but still doesn't work [:(]
Sunday, February 8, 2009 5:19 AM
And if I remove the importos from the view.aspx and I add them only to the code behind, I get this error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c56sdf089'.
Monday, February 9, 2009 1:35 PM
Well.
I moved the code to the code behind and I add a literal so I dont have to use the entity object on the view.
It works and actually it's better to split the code from the view, so for me is SOLVED.
Any way, the problem is there. Is very extrange that when you import:
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.Entity" %>
Says:"The type or namespace name 'Entity' does not exist in the namespace 'System.Data' "
Why is trying to find Entity in System.Data? Instead of System.Data.Entity? I tried also with changing the order but doesn't work.
Friday, January 22, 2010 6:20 AM
Thanks gporras, your suggestion fixed a similar problem I was having in a non-MVC ASP.NET project.
Tuesday, February 23, 2010 10:54 PM
Another way to fix this problem (which does the same thing) is to right-click on your project, and select "Add Reference". Make sure you are on the .NET tab, and scroll down till you find "System.Data.Entity" and press OK.
Thursday, May 27, 2010 4:59 PM
Does anyone know why we have to add the entry to web.config to get this working?
Is this a bug in ASP.net the fact that the import statement in the view doesn't work?
thanks
Saturday, July 10, 2010 5:28 PM
Same problem here, ASP.NET 4. Visual Studio seems to neglect adding that particular assembly to the .config.
I need to hunt around for the assembly's strong name.
Wednesday, August 4, 2010 12:19 PM
Thanks a lot gporras, this helped me so much
Tuesday, October 26, 2010 10:41 AM
Thanks, i keep forgetting about that one and your post is the one that reminds me.
Appreciated.
Saturday, May 7, 2011 10:27 PM
Another way to fix this problem (which does the same thing) is to right-click on your project, and select "Add Reference". Make sure you are on the .NET tab, and scroll down till you find "System.Data.Entity" and press OK.
I just wanted to say thnaks. your post help me to solve my issue.
Thursday, June 23, 2011 11:20 PM
Thanks it did the trick!
Sunday, November 13, 2011 8:29 PM
Is this a bug in ASP.net the fact that the import statement in the view doesn't work?
@callagga - This is probably not enabled by default to encourage use of the repository pattern as a way to access data. Normally the View doesn't directly interact with the datastore, it does so through proxy objects or POCOs for the ViewModel