Unable to determine the principal end of an association between the types '***. The principal end of

EntityFramework 数据库表 如果是一对一的主键关系时要加【Required】,不然会出错Unable to determine the principal end of an association between the types

Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

	public partial class TicketInventory
	{
		[Required]
		public TicketPurchase TicketPurchase { get; set; }
	}

表关系如下图: 采购表[TicketPurchase]、库存表[TicketInventory]关系:1对1

      public TicketInventoryEntityTypeConfiguration()
        {
		    this.ToTable("TicketInventory");
            this.HasKey(c => c.ID).Property(p => p.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

			//this.HasKey(m => m.FK_TicketPurchase).Property(m => m.FK_TicketPurchase);
			this.HasRequired(t => t.TicketPurchase).WithOptional(t => t.TicketInventory);
		}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值