- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我花了过去三个小时试图解决这个问题,最后放弃了(我会解决这个问题)。但是......只是为了确定......是否没有办法在 EF6 Fluent API 中设置单向 0:1/1:1?
考虑:
CREATE TABLE LegacyUsers (
ID INT NOT NULL PRIMARY KEY,
UserName NVARCHAR(50),
EmployeeID INT NULL
)
CREATE TABLE Employees (
ID INT NOT NULL PRIMARY KEY,
EmployeeName NVARCHAR(50)
)
领域模型:
public class LegacyUser {
public int ID {get;set;}
public int? EmployeeID {get;set;}
public virtual Employee Employee {get;set;}
}
public class Employee {
public int ID {get;set;}
public string EmployeeName {get;set;}
}
“流利”(哈哈)API理论设置:
modelBuilder.Entity<LegacyUser>()
.HasOptional(x => x.Employee)
.WithForgeignKey(x => x.EmployeeID)
我已经研究了几个小时,并尝试了多种方法来配置它。由于我的努力,我得到了“列名已存在”验证错误或“无效列:Employee_ID”错误的返回(如果这是双向的,我可以很容易地修复这些错误,但这是一个或多或少的锁定模式)。我发现唯一会迫使它工作的是将它作为 1:M 关系进行尝试,这通过必须将域模型属性用作集合而不是简单的单一关系来摆脱整个“流畅性”属性(property)。
真的没有办法像我认为的那样容易吗?要求非常简单:根据遗留用户文件中的员工 ID 获取关联的员工对象(无需破坏模型或向数据库添加新字段)
(供引用):
最佳答案
The only thing that I've found that would force it to work is to try it as a 1:M relationship, which throws off the whole "fluency" by having to use the domain model property as a collection rather than a simple, single property.
这确实是建立这种关系的唯一方法,如 Associations in EF Code First: Part 5 – One-to-One Foreign Key Associations 中所述。 .但是你误读了单向部分。幸运的是,“uni”部分是依赖端的单个导航属性 - 正是外键属性所在的位置。
所以你的模型没问题,你只需要这样设置:
modelBuilder.Entity<LegacyUser>()
.HasOptional(e => e.Employee)
.WithMany()
.HasForeignKey(e => e.EmployeeID)
.WillCascadeOnDelete(false);
关键部分是无参数的 WithMany
调用。
关于c# - EF6 FluentAPI,0 :1 Unidirectional,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40136722/
我花了过去三个小时试图解决这个问题,最后放弃了(我会解决这个问题)。但是......只是为了确定......是否没有办法在 EF6 Fluent API 中设置单向 0:1/1:1? 考虑: CREA
当我从我的实体类自动生成我的表时,我对 JPA 如何处理 1:1 单向关系感到困惑,而如果我自己创建 SQL 表,我将如何制作这些表。 我的问题是关于外键是如何设置的。 假设我有一个 Customer
我有几个关于 JPA 最佳实践(通过 hibernate )的小问题。 我的第一个问题是关于一个领域模型的复杂性。我有一个模型帐户,它代表一个...帐户;)一个帐户与其他对象有很多关系。其中很多需要被
以下数据库架构: 员工[EMP_ID (PK)、姓名、工资] 电话[ID (PK)、number_str、OWNER_ID (FK)] Employee_aud[EMP_ID (PK)、REV (PK
我正在开发一个带有垂直过渡(并且没有箭头)的 Bootstrap 3 轮播。它有效,但我正在寻找特定的过渡。 .carousel.vertical { position: relative; }
我正在尝试用 C++ 实现 Opus 转码器,但我有一些概念性问题。至于useinbandfec这个参数,不太明白“unidirectional receive-only parameter”的意思,
Angular的“单向数据流规则”被提及several times in the docs但是 Angular 文档在任何地方都没有清楚地(强调清楚地)定义单向数据流规则。 以下是我能找到的与单向数据
我正在尝试从我从服务器获得的许多项目中实现无限滚动,但我找不到任何适当的方法来保持通量架构设计规则。 想法是:在第一次加载时,我从服务器获取完整的项目列表(只有 id),然后使用 ajax 每次获取
我有一个数据库,其中包含一个 ProbateCases 表和一个 Properties 表。 ProbateCases 表有一个名为 ProbateCaseId 的 ProbateCases 表的外键
我目前在使用 OneToMany/ManyToOne 映射时遇到问题。映射看起来像这样: public class A implements Serializable { @EmbeddedI
我有一个Subscription 类和Payment 类。当我执行以下操作时,它不会在连接表中创建记录。我应该使用中间类还是可以在没有它的情况下创建这样的记录? subscriptionReposit
我正在使用 Spring 3 + Hibernate 做一个项目。当我尝试获取包含对象 PoaUpa 的对象时。我得到 java.sql.SQLException: ORA-00918 这个单向连接:
我的目标是: 创建通用关联,其中第一个实体(例如类别) 可以多次用于其他对象(例如帖子、文章) 示例 Post 有类别,Article 也有类别,但 Article 和 Post 是完全不同的实体。
我是一名优秀的程序员,十分优秀!