I am using entities, C# and SQL Server to create an n-tier app. I am creating some base classes common to all my DAL components. In this base class, i want to handle the connection state of the ObjectContext base class inherited by entities object.
Compiling throws the following error:
The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Also, the using statement System.Data.Objects doesn't resolve for the same reason.
I tried adding the assembly as reference, but couldn't find it in the .NET tab of assembly references.
Any thoughts? Thanks!
You need to add a reference to the .NET assembly System.Data.Entity.dll.
If you are using Entity Framework 6, the name space has changed. You want to use
System.Data.Entity.Core.Objects.ObjectQuery
Upgraded from EF5 to EF6 nuget a while back and kept encountering this issue. I'd temp fix it by updating the generated code to reference System.Data.Entity.Core.Objects
, but after generation it would be changed back again (as expected since its generated).
This solved the problem for good:
http://msdn.microsoft.com/en-us/data/upgradeef6
If you have any models created with the EF Designer, you will need to update the code generation templates to generate EF6 compatible code. Note: There are currently only EF 6.x DbContext Generator templates available for Visual Studio 2012 and 2013. Delete existing code-generation templates. These files will typically be named
if you want to use "System.Data.Objects.EntityFunctions"
use "System.Data.Entity.DbFunctions" in EF 6.1+
Same problem in VS 2013
I added in Web.config :
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
It worked like a charm.
I found it on page: http://www.programmer.bz/Home/tabid/115/asp_net_sql/281/The-type-or-namespace-name-Objects-does-not-exist-in-the-namespace-SystemData.aspx
In my case for EF 6+, when using this:
System.Data.Entity.Core.Objects.ObjectQuery
As part of this command:
var sql = ((System.Data.Entity.Core.Objects.ObjectQuery)query).ToTraceString();
I got this error:
Cannot cast 'query' (which has an actual type of 'System.Data.Entity.Infrastructure.DbQuery<<>f__AnonymousType3<string,string,string,short,string>>') to 'System.Data.Entity.Core.Objects.ObjectQuery'
So I ended up having to use this:
var sql = ((System.Data.Entity.Infrastructure.DbQuery<<>f__AnonymousType3<string,string,string,short,string>>)query).ToString();
Of course your anonymous type signature might be different.
HTH.
I added a reference to the .dll file, for System.Data.Linq, the above was not sufficient. You can find .dll in the various directories for the following versions.
System.Data.Linq C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.Linq.dll 3.5.0.0
System.Data.Linq C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Data.Linq.dll 4.0.0.0
You need to add a reference to the .NET assembly System.Data.Linq
Success story sharing