Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Default values not supported error' when working with Entity Framework Code First and SQLServer Compact 4.0

I am trying both xunit and TestDriven.Net for testing, for database using SQL CE4. Here is the entity definition:

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

And here is the test method:

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

XUnit passes the method while TestDriven fails with the message - 'System.NotSupportedException : Default values not supported'.

Surprisingly- if I add another property to the entity (e.g. ProductName), TestDriven also pass. Could anyone give me some clue why this is happening?

like image 722
Samina Avatar asked Apr 18 '26 01:04

Samina


1 Answers

I'm getting the same error and while searching I found this: http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/583c7839-22a4-460e-8665-3e5e3998a0d5

Looks like it's a known bug.

like image 76
Elias Avatar answered Apr 23 '26 05:04

Elias