简体   繁体   English

命名空间“System.Data”中不存在类型或命名空间名称“Objects”

[英]The type or namespace name 'Objects' does not exist in the namespace 'System.Data'

I am using entities, C# and SQL Server to create an n-tier app.我正在使用实体 C# 和 SQL 服务器来创建 n 层应用程序。 I am creating some base classes common to all my DAL components.我正在为我的所有 DAL 组件创建一些通用的基类。 In this base class, i want to handle the connection state of the ObjectContext base class inherited by entities object.在这个基础 class 中,我想处理由实体 ZA8CFDE6331149EB2AC966F9 继承的 ObjectContext 基础 class 的连接 state

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?)命名空间“System.Data”中不存在类型或命名空间名称“Objects”(您是否缺少程序集引用?)

Also, the using statement System.Data.Objects doesn't resolve for the same reason.此外,由于同样的原因,using 语句 System.Data.Objects 无法解析。

I tried adding the assembly as reference, but couldn't find it in the .NET tab of assembly references.我尝试将程序集添加为参考,但在程序集参考的 .NET 选项卡中找不到它。

Any thoughts?有什么想法吗? Thanks!谢谢!

您需要添加对.NET程序集System.Data.Entity.dll的引用。

If you are using Entity Framework 6, the name space has changed. 如果您使用的是Entity Framework 6,则名称空间已更改。 You want to use 你想用

System.Data.Entity.Core.Objects.ObjectQuery

Upgraded from EF5 to EF6 nuget a while back and kept encountering this issue. 从EF5升级到EF6 nuget一段时间后仍然遇到这个问题。 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). 我会通过更新生成的代码来引用System.Data.Entity.Core.Objects来修复它,但是在生成之后它会再次被更改回来(正如预期的那样生成它)。

This solved the problem for good: 这解决了这个问题:

http://msdn.microsoft.com/en-us/data/upgradeef6 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. 如果您使用EF Designer创建了任何模型,则需要更新代码生成模板以生成与EF6兼容的代码。 Note: There are currently only EF 6.x DbContext Generator templates available for Visual Studio 2012 and 2013. 注意: 目前只有Visual Studio 2012和2013可用的EF 6.x DbContext Generator模板。

  1. Delete existing code-generation templates. 删除现有的代码生成模板。 These files will typically be named <edmx_file_name>.tt and <edmx_file_name>.Context.tt and be nested under your edmx file in Solution Explorer. 这些文件通常被命名为<edmx_file_name> .TT<edmx_file_name> .Context.tt下在解决方案资源管理您的EDMX文件嵌套。 You can select the templates in Solution Explorer and press the Del key to delete them. 您可以在解决方案资源管理器中选择模板,然后按Del键删除它们。
    Note: In Web Site projects the templates will not be nested under your edmx file, but listed alongside it in Solution Explorer. 注意: 在“网站”项目中,模板不会嵌套在edmx文件下,而是在“解决方案资源管理器”中与其一起列出。
    Note: In VB.NET projects you will need to enable 'Show All Files' to be able to see the nested template files. 注意: 在VB.NET项目中,您需要启用“显示所有文件”才能看到嵌套的模板文件。
  2. Add the appropriate EF 6.x code generation template. 添加适当的EF 6.x代码生成模板。 Open your model in the EF Designer, right-click on the design surface and select Add Code Generation Item... 在EF Designer中打开模型,右键单击设计图面并选择Add Code Generation Item ...
    • If you are using the DbContext API (recommended) then EF 6.x DbContext Generator will be available under the Data tab. 如果您使用的是DbContext API(推荐),那么EF 6.x DbContext Generator将在Data选项卡下可用。
      Note: If you are using Visual Studio 2012, you will need to install the EF 6 Tools to have this template. 注意: 如果您使用的是Visual Studio 2012,则需要安装EF 6 Tools才能使用此模板。 See Get Entity Framework for details. 有关详细信息,请参阅Get Entity Framework
    • If you are using the ObjectContext API then you will need to select the Online tab and search for EF 6.x EntityObject Generator . 如果您使用的是ObjectContext API,则需要选择Online选项卡并搜索EF 6.x EntityObject Generator
  3. If you applied any customizations to the code generation templates you will need to re-apply them to the updated templates. 如果您将任何自定义应用于代码生成模板,则需要将它们重新应用于更新的模板。

Same problem in VS 2013 VS 2013中的问题相同

I added in Web.config : 我在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 我在页面上找到了它: 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: 在我的EF 6+案例中,使用时:

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. HTH。

if you want to use "System.Data.Objects.EntityFunctions" 如果你想使用“System.Data.Objects.EntityFunctions”

use "System.Data.Entity.DbFunctions" in EF 6.1+ 在EF 6.1+中使用“System.Data.Entity.DbFunctions”

您需要添加对.NET程序集System.Data.Linq的引用

I added a reference to the .dll file, for System.Data.Linq, the above was not sufficient. 我添加了对.dll文件的引用,对于System.Data.Linq,上面的内容还不够。 You can find .dll in the various directories for the following versions. 您可以在以下版本的各个目录中找到.dll。

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 \\ 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 System.Data.Linq C:\\ Program Files(x86)\\ Reference Assemblies \\ Microsoft \\ Framework.NETFramework \\ v4.0 \\ Profile \\ Client \\ System.Data.Linq.dll 4.0.0.0

For EF6, replace "xxxx.Context.cs" with these using对于 EF6,将“xxxx.Context.cs”替换为这些使用

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using System.Linq;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 命名空间“System.Data”中不存在类型或命名空间名称“实体” - The type or namespace name 'Entity' does not exist in the namespace 'System.Data' 类型或名称空间名称“ OracleClient”在名称空间“ System.Data”中不存在 - The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' 类型或名称空间名称“ SQLite”在名称空间“ System.Data”中不存在 - The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' 错误 CS0234:命名空间“System.Data”VSTS (DevOps) 中不存在类型或命名空间名称“实体” - Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' VSTS (DevOps) 类型或名称空间名称“ OleDb”在名称空间“ System.Data”中不存在(您是否缺少程序集引用?) - The type or namespace name 'OleDb' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) 命名空间“System.Data”中不存在类型或命名空间名称“SQLite”(您是否缺少程序集引用?) - The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) 名称空间&#39;System.Data&#39;中不存在类型或命名空间名称&#39;DataSetExtensions&#39;(您是否缺少程序集引用?) - The type or namespace name 'DataSetExtensions' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) LINQ to SQL,命名空间“System.Data”中不存在“Linq” - LINQ to SQL, 'Linq' does not exist in the namespace 'System.Data' 命名空间“系统”中不存在类型或命名空间名称“数据” - Type or namespace name 'Data' does not exist in the namespace 'System' 命名空间“System.Windows”中不存在类型或命名空间名称“部署” - The type or namespace name 'Deployment' does not exist in the namespace 'System.Windows'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM