【问题标题】:SubSonic3 - Column 'CategoryID' cannot be nullSubSonic3 - 列“CategoryID”不能为空
【发布时间】:2009-09-24 15:51:45
【问题描述】:

我将 Subsonic 与 SimpleRepository 一起使用:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic.DataProviders;
using SubSonic.Repository;

namespace SubSonicTest
{
    class Program
    {
        public class Product
        {
            public int ProductID { get; set; }
            public int CategoryID { get; set; }
            public string ProductName { get; set; }
            public decimal UnitPrice { get; set; }
            public bool Discontinued { get; set; }


        }
        static void Main(string[] args)
        {

            var repo = new SimpleRepository("SubSonic", SimpleRepositoryOptions.RunMigrations);
            var newProduct = new Product();
            newProduct.CategoryID = 5;
            newProduct.ProductName = "Pretzel";
            newProduct.UnitPrice = 100;
            newProduct.Discontinued = false;
            repo.Add<Product>(newProduct);
        }
    }
}

但是,当我运行它时,我得到: Column 'CategoryID' cannot be null 这是 MySQL 和 windows 以及 VS2008。有什么想法吗?

谢谢

【问题讨论】:

    标签: c# mysql subsonic subsonic3


    【解决方案1】:

    尝试更改您的类属性定义;

    public int? CategoryID { get; set; }
    

    您不能将 int 类型设置为 null。

    【讨论】:

    • 虽然奇​​怪的是他的代码似乎指定了一个 CategoryID 值。
    • 我在想也许构造函数试图将属性设置为空?我知道这听起来很疯狂,但我想如果这能奏效,那就太好了!
    猜你喜欢
    • 2014-03-08
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2019-07-10
    相关资源
    最近更新 更多