views:

52

answers:

1

I'm using Subsonic with 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. Any ideas?

Thanks

+1  A: 

Try changing your class property definition;

public int? CategoryID { get; set; }

You cant set the int type to null.

CmdrTallen
Although strangely his code seems to specifying a CategoryID value.
Adam
I was thinking perhaps the contructor was trying to set the property to null? I know sounds crazy, but I figured if that made it work then hoorah!
CmdrTallen