问题标签 [ef4-code-only]
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.
c# - 具有 EntityFramework CodeOnly 的基本类型
我在实体框架的仅代码模型中的“基本类型”遇到了很多麻烦。我在实体框架的仅代码模型中的“基本类型”遇到了很多麻烦。
当我尝试使用 aDbContext
和 a运行此代码时DbSet<Template>
,出现以下错误。
A 导航属性“Flags”映射到两个不同的连接表“page.flags”和“template.flags”。导航属性可能只存在一个映射
这对我说的是我无法映射继承的属性。这对许多面向对象的代码设计来说是相当大的突破。有已知的补救措施吗?我意识到我可以使 Layout 成为非抽象的,并且有支持,但很明显这不是领域模型的意图。抽象类是基础,而不是存储模型。
我想补充一点,如果我把它IList<Flag>
放在Template
类中,这段代码就会运行。Id
即使通过继承,该领域仍然有效。我不明白为什么会这样。有人可以启发我吗?
entity-framework-4 - 我如何创建一个复合键,它首先包含一个外键和代码?
我首先使用 EF4 代码,并希望生成一个由类属性和外键组成的复合键。我有两个课程:订单和公司。Order 类包含一个引用,但这在公司之间不一定是唯一的。所以我打算使用由 Reference 和 Company.CompanyId 组成的复合键。
我尝试使用以下方法进行设置,但收到错误消息“键表达式无效”。
我也试过
这失败了。
这些是我的课:
任何帮助将不胜感激。
orm - 仅 EF4 代码 - 将列映射到属性复杂类型
我有一张这样的桌子:
- 姓名
- 树
- 铁
- 粘土
- 添加
我想将它映射到这样的模型:
- 姓名
- 资源
- 树
- 铁
- 粘土
- 添加
在我的程序中使用它时,像这样映射它是有意义的,但是在数据库中这样做只会使它更复杂......不会添加任何有用的东西。
是否可以仅使用 EF4 代码?
entity-framework-4 - 仅在 EF4 代码上创建数据库后更改模型
嘿,抱歉我的英语不好...仅使用 EF4 代码,我创建了一些 POCO 类,并且我的数据库是从中生成的。一切正常,我在表上插入了一些数据,但现在我需要在我的一个类上创建一个新属性。如果我只是创建它,应用程序会给我一个例外: {“自从创建数据库以来,支持'TestContext'上下文的模型已经更改。手动删除/更新数据库,或者使用 IDatabaseInitializer 实例调用 Database.SetInitializer。对于例如,RecreateDatabaseIfModelChanges 策略将自动删除并重新创建数据库,并可选择为其添加新数据。"}
我试图在表上手动创建字段,但它仍然在抱怨......有人知道是否有办法,如果有,我该如何手动更新数据库架构(我不想重新创建它,因为我已经有数据)来匹配模型?
entity-framework - EF4 CTP4 Code First 中带有附加列的联结表
鉴于此 sql 架构:
如何在 ? 中定义复合主键和附加列EntityConfiguration
?
entity-framework - 如何将图像类型添加到 EF4 代码优先实体?
如何将图像类型添加到 EF4 代码优先实体?我需要为缩略图添加一列。
谢谢!
entity-framework - 仅 EF4 代码 + Ria 服务
我想我可以将我的 DbContext 与 DomainService 一起使用,就像我在任何 MVC 应用程序中使用它一样:
事情是,当 Query 工作时,Delete 和 Update 操作会抛出异常,例如:
“无法删除该对象,因为它在 ObjectStateManager 中找不到。”
更新:解决方案
所以这就是我最终要做的。仍然不确定这是否是正确的方法:
asp.net-mvc - EF 4 代码如何首先处理生产环境中的架构更改?
传统上,我总是手工编写我的 sql 脚本,因此它们既漂亮又干净(我不喜欢生成的脚本)并且发布到发布,我提供了一个全新的安装脚本和一个来自以前版本的迁移脚本,它创建了新的表,更改现有表等。这都是非常标准的。
我真的没有太多时间先玩 EF 4 代码,但如果它在生产环境中实际上是可行的,我很感兴趣使用它。
假设您有一种代码优先的方法,如果数据库不存在,将自动创建数据库。如果您发布具有架构/模型更改的新版本软件会发生什么。EF 是否足够智能以更新数据库架构以匹配更新后的 EF 模型?
设想
- 客户端在其服务器上安装 asp.net MVC 网站。首次运行时,会创建一个新数据库
- 客户使用网站一段时间,数据库中填充了一些数据
- 同时发布了新版本的网站,并更改了 EF 模型
- 客户端下载新版本,部署网站并指向现有数据库
代码首先只对初始部署有用,还是足够聪明地更新现有数据库版本以像这样发布?
.net - EF4 TPT with abstract classes - defining relationships
I've been going around in circles with this and don't seem to be able to google the right answers - even after hours spent on this, so you're my last resort!
Setup
In my web app I would like to enable users to use different authentication mechanisms to access their accounts. In addition to the usual user/password thing I'd like to enable them to use Google's OpenId, Yahoo's OpenId, or even Facebook. This seems rather straightforward to map into classes: an abstract Account
with several <something>Account
classes inheriting some basic properties from Account
. I started with the following two classes:
Being a bit of a perfectionist, and doing a lot of db dev in my day job, I decided table per type (TPT) would be the most desirable option. As EF4 uses TPH by default, on the DbContext side of things I defined:
Now, I wished to start with some simple tests, and thought that seeding the database on each run was a good way to have consistent data to work with:
(Not sure why but DbContext didn't seem to ever try populate my db with the above data until I exlicitly called .SaveChanges()
... any ideas?)
The Problems
One
In the database, EF didn't define any relationships between Account
and OpenIdAccount
. This was the first warning sign something was not right; surely OpenIdAccount should have its Id
defined as both a PK and a FK pointing at Account.Id?
Two
I get the following UpdateException
when .net tries to execute .SaveChanges()
:
A value shared across entities or associations is generated in more than one location. Check that mapping does not split an EntityKey to multiple store-generated columns.
Next steps
Today is my first day with EF4 and code first development. Having spent numerous hours reading about EF4 + code-first + custom mapping I came to a point where I'm permanently stuck and need a kick in the right direction before I can get going again :-)
So I'm hoping that you guys can make sense of the above and explain some silly mistake / misunderstanding on my part!
asp.net-mvc-2 - 如何首先使用 EF4 代码重新创建数据库进行测试
我在我的 .net MVC 2.0 项目中使用 Entity Framework 4 Code First,我很难让我的数据库与我的实体同步。我想要的是一个我可以调用的页面,例如:/DB/Recreate,它将删除我当前的数据库并重新创建一个空的。目前在我的 global.asax 我有
我尝试在我的操作中切换我的数据库初始化程序,但我真的不确定,因为它应该已经被初始化,我正在使用正确的方法:
我真的不知道该怎么做,谢谢你的帮助!