问题标签 [entity-framework-6]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
6861 浏览

entity-framework - 使用 EF6 连接到 SQL Server

在 EF5 之前,为了连接到 SQL Server 2012,我只需要指定一个如下所示的连接字符串:

此方法不适用于 EF6,出现异常

找不到“System.Data.Odbc”ADO.NET 提供程序的实体框架提供程序。确保提供程序已在应用程序配置文件的“entityFramework”部分中注册

我根本没有使用app.config文件,我将上面的连接字符串传递给 MyContext 构造函数。为什么它试图使用 Odbc 提供程序,而不是使用 System.Data.SqlClient?

使用 EF6 代码优先连接到 SQL Server 需要做什么?我确保 EntityFramework.dll 和 EntityFramework.SqlServer.dll 在 Application 文件夹中都可用。我什至在 WPF 项目中添加了 EF6 nuget 包 v6.0.0.1,尽管它不直接使用 EF 库,并确保将自动创建的 App.Config 文件(由 nuget)复制到 Application (Debug) 文件夹 - 仍然没有成功。

我还尝试在代码中手动设置提供者:

仍然没有成功。我的项目结构如下(简化):

WPF 项目 - 没有对 EF 的引用(也尝试添加 EF 引用)

ViewModel 类库 - 没有对 EF 的引用

模型类库 - 引用了 EF 库(两个 dll)

数据类库 - 引用了 UI 库(两个 dll)。

我正在使用 CodeFirst 方法,并且此设置对 EF5 没有任何问题。任何帮助是极大的赞赏。

0 投票
1 回答
852 浏览

entity-framework - 带有 EF 6 的 Mono 3 - 有人有运气吗?

我正在尝试获得一个概念验证应用程序,它使用 Entity Framework 6 和 Mono 3.0.6 - 经过 2 天的试验,我放弃了。我可以查看周围的任何示例应用程序吗?我用谷歌搜索 - 没有运气。

我试图使用来自 mono/GAC 的“EntityFramework.dll”库——在这种情况下,项目甚至没有进入 main() 函数——在那之前我得到了 IL 异常。

我尝试从 NuGet 下载 EF6 alpha 3 - 但随后项目在执行过程中崩溃:

所以我不确定发生了什么。Mono 团队说 EF 是半年前作为 Mono 的一部分发货的——有人用过吗?

我将不胜感激任何链接或源代码或提示让这件事继续下去。

谢谢!

0 投票
1 回答
688 浏览

entity-framework - EF 6 - 多对多 - 无重复连接表

我正在使用 EF6 对播种多对多关系有些困惑。

我有以下内容:

A保存User许多ChartQueries(他们可以执行以获取图表)。AChartQuery通常只属于一个用户,但是每个用户都可以执行多个“共享ChartQueryUser。结果,我使用连接表建立了多对多UserChartQuery关系。这些表在连接表的每一侧以一对多的方式在数据库中正常运行。

但是,我不太了解如何播种或使用这种关系。我不想最终得到“shared” ChartQuerys 的多个副本(每个副本都有一个副本User)。相反,每个“共享”应该只有一行,ChartQuery它是 each 集合的一部分 User(以及仅属于该SavedChartQueries集合的其他非共享s )。ChartQueryUser

似乎我被迫为每个用户复制:

所以首先这是播种的正确方法(直接通过 UserChartQueries 表)还是我应该播种每个User的 SavedChartQueries 导航属性?

这会导致sharedChartQuery每个连接表中的重复User吗?如果是这样,有什么办法可以避免这种情况?

0 投票
2 回答
7287 浏览

entity-framework - 错误“无法设置 MyNamespace.MyCustomInitializer、MyAssembly 类型的数据库初始化程序”无法加载 MyContext 类型

我正在使用 .NET4.5 和 Entity Framework 6 alpha3 创建一个 Web 应用程序,该应用程序使用新的 SQL Compact 数据库。该数据库尚不存在。

我在 Web 表单中有以下代码:

其中 JournalistContext 派生自 DbContext。它创建了 JournalistContext 的实例 ok,但是在执行下一行时,它抛出了下面的异常。我猜由于数据库不存在,它试图调用初始化程序,但这失败了。

如此处所述http://msdn.microsoft.com/en-us/data/jj556606我创建了一个自定义数据库初始化程序,目前是一个空白类:

我的 web.config 文件引用了这个初始化器,如下所示:

我难住了!有任何想法吗?

我注意到的另一件事:这些行出现在我的 web.config 文件中。我不确定它们是如何添加的,或者为什么。

非常感谢,马克。

0 投票
2 回答
12833 浏览

c# - EF 中 IDatabaseInitializer 的正确用法是什么?

我有一个自定义的 DatabaseInitialiser,它在下面

关于上述代码的一些东西不仅仅是hacky(请随时提供帮助)

然后我添加了迁移并使迁移脚本也能正常工作。

迁移按预期工作。

现在,问题是在我的应用程序启动中我应该怎么做?像这样的东西

并且一些论坛也在构造函数中提出了这一点,这似乎有点奇怪,因为我不想在每次使用上下文时检查数据库和模式是否正确。那么,这种技术的可能用途是什么,或者我认为建议的上下文是错误的?

总结一下,

  1. 可用的不同技术的正确用例是什么?

  2. 什么是理想的策略,以便迁移在所有条件下以及当我们将数据库从一个环境移动到另一个环境时工作?

0 投票
4 回答
8191 浏览

c# - 实体框架 6 无法检索元数据

我正在使用 EF 6 pre-3。

产品型号:

}

创建控制器时,出现以下错误:

上下文是:

我的连接字符串是:

0 投票
0 回答
289 浏览

entity-framework - 实体框架 6 中的 STE 可用性

如果实体框架 6 中支持 STE(自我跟踪实体),我找不到信息。如果有人知道答案,我将不胜感激。

我在看 EF 网站,但没有关于 STE 的消息。

谢谢你。

0 投票
0 回答
348 浏览

sql-server-2008 - What is the Windows overhead when using SQL Server varchar vs. nvarchar?

I do not have need for foreign language characters or collation since my data is received as pure ascii.

My concern is performance in the application code, and though I have read many arguments that varchar performs better than nvarchar, they did not discuss the overhead converting back and forth between Windows Unicode and SQL Server non-Unicode varchar data?

What is the bigger impact in general - performance within SQL Server dealing with varchar vs. nvarchar, or performance in the application, converting back and forth between Unicode on the Windows side and non-Unicode on the SQL Server side? I understand there are scenarios where one would perform better than other, so my main scenario is simple text search and retrieval through a couple million records. I am using Entity Framework 6.1.3 as the DAL.

This is a concern and I would love some feedback on this from anyone having experimented or knowledgeable on this topic. Articles discussing varchar vs. nvarchar act like the SQL database is totally isolated in respect to performance and external software does not come into play. Is there in fact Unicode impedance mismatch between Windows native use of Unicode and ascii in the database, storage space and transfer speeds ignored, that negates the ascii database performance benefits? Especially in relation to EF? Thanks

0 投票
1 回答
930 浏览

c# - Many-to-many without an inverse property

I want to create a many-to-many relationship in EF. Normally I would use the InverseProperty attribute, however, in this case:

#xA;

I don't have an inverse property. How to tell EF that a privilege may be used in more than one Role?

[ Currently EF puts a Role_Id column in the Privilege table. This is not what I want :-) ]

Edit: I do not want to use the Fluent API, I'm looking for an attribute.

0 投票
0 回答
306 浏览

c# - SQL 查询和 OFType

我确实升级到了 EF 6,但我不知道如何迁移这种情况,如何使用SQLQueryOFType