gpt4 book ai didi

c# - SubSonic3 - 列 'CategoryID' 不能为空

转载 作者:行者123 更新时间:2023-11-29 15:08:23 26 4
gpt4 key购买 nike

我将 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);
}
}
}

但是,当我运行此命令时,我得到:列“CategoryID”不能为空这是 MySQL 和 Windows 以及 VS2008 的情况。有什么想法吗?

谢谢

最佳答案

尝试更改类属性定义;

public int? CategoryID { get; set; }

不能将 int 类型设置为 null。

关于c# - SubSonic3 - 列 'CategoryID' 不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1472576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com