- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有这门课:
public class Message
{
public long Id { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
public virtual Message ParentMessage { get; set; }
public virtual Message ChildMessage { get; set; }
//...
}
使用 EntityFramework
Code First
Add-Migration
给我消息:Unable to determine the principal end of an association between the类型...
我不能使用[Required]
属性,因为该线程中的第一条消息没有父消息,线程中的最后一条消息也没有子消息...我该如何映射这个?
我试过:
modelBuilder.Entity<Message>()
.HasOptional(x => x.ParentMessage);
modelBuilder.Entity<Message>()
.HasOptional(x => x.ChildMessage);
但这没有用。
最佳答案
我发现了一些看起来可能是它的东西,如果有人可以验证这是正确的:
modelBuilder.Entity<SecureMessage>()
.HasOptional(x => x.ParentMessage)
.WithOptionalDependent(x => x.ChildMessage);
所以经过一些认真的测试,这似乎确实是解决方案。
关于c# - EntityFramework Code First自引用一对一(1 :1) relationship mapping - Unable to determine the principal end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19825848/
我在使用一对一映射时遇到问题。我搜索了互联网并找到了许多解决方案,但没有一个令人满意。大多数示例都带有将父实例存储在子类中的开销。 我只想在具有外键约束关系的子类中使用父 ID,但不想在子类中保留任何
我有以下设置: Micronaut 3.x Java 15 我要更新的实体: @Setter @Getter @Entity @ToString @Table(name = "single_choic
我正在使用AVAudioPlayer制作MP3播放器。我有多种MP3声音,想一一播放。以下是我的应用程序的逻辑: ///// For playing 1st sound mp3Player = [[A
所以这就是问题所在。我有 2 个模型: 裁判级别和裁判 两个都有: class RefereeLevel(models.Model): level = models.PositiveSmall
我想将数组添加到列表或多维数组(不是一次全部...)。但是我真的不明白为什么这应该那么难。 可以说我有这个: string[] a = { "h", "b"}; string[] b
我有一个长度为 1000 的数字序列,我将其分成 100 个长度的序列。所以我最终得到了 901 个长度为 100 的序列。让前 900 个序列为 trainX。 trainY 是这些序列中的第 2
关键字:association 一对一映射(一个班级只有一个班主任) ?
所以,这是我第一次学习计算机语言。我选择了python和django。现在,我了解了 python 和 django 的许多基本概念。我可以使用 View 和所有其他内容创建新页面。但我仍然对这些关系
在一对一映射中,我编写了以下代码行。 @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Paramet
我有两个如下所示的实体 @Data @EqualsAndHashCode(callSuper = true) @Entity @Table(name = "foo") @Audited @AuditO
我的问题很简单.. 假设有 2 个类..书籍和作者 假设一本书只能由一位作者撰写。 一个作家可以写很多本书。 假设作者有唯一的名字。 [两个作者不能同名] 现在..假设所有 hibernate\JPA
我正在尝试创建一个实体,如下所示 @Data public class Person { @Id private String id; @OneToMany(mapp
我有一个包含字段的Project表 ID PROJECT_BASELINE_ATTRIBUTES_ID (FK for table PROJECT_BASELINE_ATTR) 这个表有如下映射
我正在学习基本的 hibernate 教程。我正在尝试在 2 个表之间建立一对一的关系。当我尝试插入 Client 表时它起作用了,但是当我尝试做相反的事情时(插入 Facture 表)我得到了这个异
我已经在 hibernate 3 中使用注释完成了一对一映射,我有两张表“组”和“类别”。类别是预定义的。当用户选择类别和组时,CategoryId和goupid应该只插入组表中。 那么应该如何映射。
我使用Linux服务Fedora 4.14.33-51.37.amzn1.x86_64。我想使用 NAT 1 对 1。例如是否相同problem我的方案是:我的服务器有两个网络接口(interface
我正在尝试与实体 Revision 创建一对一、自引用、双向关系(哇),看起来像这个: /** * @Entity() * @Table(name="rev") */ class Revisio
我需要两个实体之间的链接,所以我使用一对一 @Entity @Table(name = "T_USER") public class User implements Serializable {
一对一: 一对一的关系极为一个数据仅对应一个数据,用下图的结构图可以帮助理解: 下面用代码实现一下,首先要创建工程项目如下: 接着,我们定义模型: 来到models.py文件,创建两
假设我有5列。 pd.DataFrame({ 'Column1': [1, 2, 3, 4, 5, 6, 7, 8, 9], 'Column2': [4, 3, 6, 8, 3, 4, 1, 4, 3
我是一名优秀的程序员,十分优秀!