Tag: association

如何更改关联字段的值

我有2个类,它们之间有LINQ关联,即: Table1: Table2: ID ID Name Description ForiegnID 这里的关联是在Table1.ID – > Table2.ForiegnID之间 我需要能够更改Table2.ForiegnID的值,但我不能并且认为这是因为关联(因为当我删除它时,它工作)。 因此,有谁知道如何更改相关字段Table2.ForiegnID的值?

必须使用关系流畅API或数据注释显式配置此关联的主要结尾

“必须使用关系流畅的API或数据注释显式配置此关联的主要结尾。” 我在更新/迁移数据库时在entity framework4.4中收到此错误,但我不是要尝试指定1:1关系。 我想要这样的东西: public class EntityA { public int ID { get; set; } public int EntityBID { get; set; } [ForeignKey(“EntityBID”)] public virtual EntityB EntityB { get; set; } } public class EntityB { public int ID { get; set; } public Nullable PreferredEntityAID { get; set; } [ForeignKey(“PreferredEntityAID”)] public virtual EntityA PreferredEntityA […]

如何使用entity framework流畅的API配置多对多关系

我试图首先在EF代码中设置多对多关系,但默认约定是错误的。 以下类描述了这种关系: class Product { public int Id { get; set; } public string Name { get; set; } } class Account { public int Id { get; set; } public string Name { get; set; } public virtual ICollection Products { get; set; } } 一个帐户可以有许多产品。 但是,EF约定将创建DB表: Products Table ————– Id Name Account_Id <- […]