【发布时间】:2020-05-18 00:08:05
【问题描述】:
抱歉,如果这看起来有点基本,我正在尝试为我正在构建的网站进行迁移,并且在创建迁移后尝试更新数据库时,我不断收到此错误。有谁知道我该如何解决这个问题?
这是模型的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BulkyBook.Models
{
public class ShoppingCart
{
public ShoppingCart()
{
Count = 1;
}
[Key]
public int Id { get; set; }
public string ApplicationUserId { get; set; }
[ForeignKey("ApplicationUserId")]
public ApplicationUser ApplicationUser { get; set; }
public int ProductId { get; set; }
[ForeignKey("ProductId")]
public Product Product { get; set; }
[Range(1, 1000, ErrorMessage = "Please enter a value between 1 and 1000")]
public int Count { get; set; }
[NotMapped]
public double Price { get; set; }
}
}
订单详情:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BulkyBook.Models
{
public class OrderDetails
{
[Key]
public int Id { get; set; }
[Required]
public int OrderId { get; set; }
[ForeignKey("OrderId")]
public OrderHeader OrderHeader { get; set; }
[Required]
public int ProductId { get; set; }
[ForeignKey("ProductId")]
public Product Product { get; set; }
public int Count { get; set; }
public double Price { get; set; }
}
}
产品:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BulkyBook.Models
{
public class Product
{
public int Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public string Description { get; set; }
[Required]
public string ISBN { get; set; }
[Required]
public string Author { get; set; }
[Required]
[Range(1, 10000)]
public double ListPrice { get; set; }
[Required]
[Range(1, 10000)]
public double Price { get; set; }
[Required]
[Range(1, 10000)]
public double Price50 { get; set; }
[Required]
[Range(1, 10000)]
public double Price100 { get; set; }
public string ImageUrl { get; set; }
[Required]
public int CategoryId { get; set; }
[ForeignKey("CategoryId")]
public Category Category { get; set; }
[Required]
public int CoverTypeId { get; set; }
[ForeignKey("CoverTypeId")]
public CoverType CoverType { get; set; }
}
}
【问题讨论】:
-
你能分享你的
OrderDetail和Product课程吗? -
你必须编辑你的帖子;p
-
哈哈,是的,我花了一分钟才弄清楚,谢谢,我现在已经更新了
标签: sql asp.net-mvc asp.net-core entity-framework-migrations