使用实体框架代码优先和 SQLServer Compact 4.0 时'Default values not supported error'



我正在尝试xunit和TestDriven。Net进行测试,对于数据库使用SQL CE4。下面是实体定义:

    public class Product 
    {
        private readonly ICollection<Inventory> inventories = new List<Inventory>();
        private int id;
        public virtual int Id { get; set; }        
        //public virtual string ProductName { get; set; }
        public virtual ICollection<Inventory> Inventories 
        {
            get { return inventories; }
        }
    }
    public class ProductConfiguration : EntityTypeConfiguration<Product>
    {
        public ProductConfiguration()
        {
           HasKey(p => p.Id); //Id column of the product is an Identity column
           Property(p => p.Id);
        }
    }

下面是测试方法:

    [Fact]
    public void WhenProductAddedItShouldPersist()
    {
        var product= ObjectMother.Single<Product>();
        productRepository.Add(product);
        unitOfWork.Commit();
        Assert.NotNull(productRepository.One(product.Id));
    }

当TestDriven失败时,XUnit传递该方法并返回消息- 'System '。NotSupportedException:默认值不支持。

令人惊讶的是-如果我添加另一个属性到实体(例如ProductName), TestDriven也通过。谁能告诉我为什么会这样?

我得到相同的错误,而搜索我发现这个:http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/583c7839-22a4-460e-8665-3e5e3998a0d5

看起来是一个已知的bug

最新更新