0

我有三个表:PropertyOwnerPropertyAddress

一个PropertyOwner有很多Properties

一个PropertyOwner有一个Address

每个属性也有一个地址

这是 Entity Framework 4.4 的代码:

Table: PropertyOwner

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Required]
public Guid PropertyOwnerId { get; set; }

[Required]
[ForeignKey("Address")]
public Guid AddressId { get; set; }
public virtual Address Address { get; set; }


Table: Property

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Required]
public Guid PropertyId { get; set; }

[Required]
[ForeignKey("PropertyOwner")]
public Guid PropertyOwnerId { get; set; }
public virtual PropertyOwner PropertyOwner { get; set; }

[Required]
[ForeignKey("Address")]
public Guid AddressId { get; set; }
public virtual Address Address { get; set; }


Table: Address

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Required]
public Guid AddressId { get; set; }

[Required]
[StringLength(64)]
public string AddressLine1 { get; set; }

当我尝试创建此数据库时,出现以下错误:

The referential relationship will result in a cyclical reference that is not allowed. [ Constraint name = FK_dbo.PropertyOwner_dbo.Address_AddressId ]

数据库是否认为PropertyAddressPropertyOwnerAddress是同一条记录?

如何在Property需要拥有自己的地址并且PropertyOwner也需要拥有自己的Address的属性中将其拼写出来?

谢谢。

4

0 回答 0