未知专栏' Productsid'在'字段列表'

时间:2017-01-13 22:25:04

标签: c# sql entity-framework

我需要第二眼。我知道错误消息是在我的表中找不到Productsid。我找不到需要改变的东西。 这是我的控制器中的方法

[HttpPost]
        [Route("orderItems")]
        public IActionResult OrderItems(string name, string quantity, string product)
        {
            var user = _context.Users.FirstOrDefault(x => x.name == name);
            var product_info = _context.Products.FirstOrDefault(x => x.name == product);
            if(product_info.quantity < Int32.Parse(quantity))
            {
                TempData["Quantity"] = true;
                return RedirectToAction("Orders");
            }

            Users_Has_Products user_products = new Users_Has_Products();
            user_products.users_id = user.id;
            user_products.products_id = product_info.id;
            user_products.quanitity = Int32.Parse(quantity);
            user_products.created_at = DateTime.Now;
            _context.Users_Has_Products.Add(user_products);
            _context.SaveChanges();


            return RedirectToAction("Orders");
        }

这是我的模特

using System;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
namespace ecommerce.Models
{
    public class Users_Has_Products
    {
        public int id { get; set; }
        public int users_id { get; set; }
        public int products_id { get; set; }
        public int quanitity { get; set; }
        public DateTime created_at { get; set; }

        public Users Users {get; set;}

        public Products Products {get; set;}
    }
}

这是我的数据库表 enter image description here

0 个答案:

没有答案