[英]SubSonic3 - Column 'CategoryID' cannot be null
I'm using Subsonic with SimpleRepository: 我在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);
}
}
}
However, when I run this, I get: Column 'CategoryID' cannot be null This is with MySQL and windows and VS2008. 但是,当我运行它时,我得到:列'CategoryID'不能为null这是MySQL和Windows和VS2008的情况。 Any ideas?
有任何想法吗?
Thanks 谢谢
Try changing your class property definition; 尝试更改您的类属性定义;
public int? CategoryID { get; set; }
You cant set the int type to null. 您不能将int类型设置为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.