我遇到了一个非常简单的关系的EF 6.x配置:-(。我希望有人可以帮助我!
这里的描述:
这些类定义如下:
public class Network
{
public int NetworkId {get; set;}
:
public int? ProductionId {get;set;}
public virtual Production Production {get;set;}
:
}
public class Production
{
public int ProductionId {get;set;}
:
public int NetworkId {get;set;}
public virtual Network {get;set;}
:
}
随附的配置是:
public NetworkMap ()
{
HasKey (p => p.NetworkId).Property (p => p.NetworkId).HasDatabaseGeneratedOption (DatabaseGeneratedOption.Identity);
HasOptional (p => p.Production).WithRequired (p => p.Network);
}
public ProductionLineMap ()
{
HasKey (p => p.ProductionLineId)
.Property (p => p.ProductionId)
.HasDatabaseGeneratedOption (DatabaseGeneratedOption.Identity);
}
如果我尝试保存'制作',我会收到以下错误:
XPRD.Location.Data.Exceptions.XPRDDbException : DbException
----> System.Data.Entity.Infrastructure.DbUpdateException : An error occurred while updating the entries. See the inner exception for details.
----> System.Data.Entity.Core.UpdateException : An error occurred while updating the entries. See the inner exception for details.
----> System.InvalidOperationException : A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'ProductionId'.
我知道这个问题与'ProductionId'有关但我不知道如何编写配置或改变类定义以实现我想要的。
我会很乐意帮助你!
干杯, 彼得